Skip to content

Commit

Permalink
backport of commit a47995f
Browse files Browse the repository at this point in the history
  • Loading branch information
hashi-derek committed Nov 3, 2023
1 parent 4d648c8 commit 149ebfd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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 @@ -46,6 +46,7 @@ type Conn struct {
refCount int32
shouldClose int32

dc string
nodeName string
addr net.Addr
session muxSession
Expand Down Expand Up @@ -231,7 +232,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 @@ -490,6 +491,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 @@ -511,7 +513,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 @@ -713,3 +715,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
}

0 comments on commit 149ebfd

Please sign in to comment.