Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NET-6459] Fix issue with wanfed lan ip conflicts. #19503

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19503.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
wan-federation: Fix a bug where servers wan-federated through mesh-gateways could crash due to overlapping LAN IP addresses.
```
11 changes: 9 additions & 2 deletions agent/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Conn struct {
refCount int32
shouldClose int32

dc string
nodeName string
addr net.Addr
session muxSession
Expand Down Expand Up @@ -234,7 +235,7 @@ func (p *ConnPool) acquire(dc string, nodeName string, addr net.Addr) (*Conn, er

addrStr := addr.String()

poolKey := nodeName + ":" + addrStr
poolKey := makePoolKey(dc, nodeName, addrStr)

// Check to see if there's a pooled connection available. This is up
// here since it should the vastly more common case than the rest
Expand Down Expand Up @@ -493,6 +494,7 @@ func (p *ConnPool) getNewConn(dc string, nodeName string, addr net.Addr) (*Conn,
// Wrap the connection
c := &Conn{
refCount: 1,
dc: dc,
nodeName: nodeName,
addr: addr,
session: session,
Expand All @@ -514,7 +516,7 @@ func (p *ConnPool) clearConn(conn *Conn) {

// Clear from the cache
addrStr := conn.addr.String()
poolKey := conn.nodeName + ":" + addrStr
poolKey := makePoolKey(conn.dc, conn.nodeName, addrStr)
p.Lock()
if c, ok := p.pool[poolKey]; ok && c == conn {
delete(p.pool, poolKey)
Expand Down Expand Up @@ -716,3 +718,8 @@ func (p *ConnPool) reap() {
p.Unlock()
}
}

// makePoolKey generates a unique key for grouping connections together into a pool.
func makePoolKey(dc, nodeName, addrStr string) string {
return dc + ":" + nodeName + ":" + addrStr
}