mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-16 23:26:52 +01:00
Attach a pending handshake's RemoteList when the handshake starts (#1909)
StartHandshake returned a hostinfo with no RemoteList; handleOutbound attached one lazily on its first tick. Anything that touched the pending host before then, notably create-tunnel -address, dereferenced nil and took the daemon down. StartHandshake now attaches the lighthouse's list as it builds the hostinfo. To keep the surrounding locking sound, a lighthouse now resolves a punch target before taking the querier's RemoteList lock, and closeTunnel deletes the host and evicts its RemoteList under a single hostmap write lock so a completing handshake cannot land in between. The lock order, now documented on the handshake manager mutex, is hostmap, then handshake manager, then lighthouse, then RemoteList; no RemoteList lock is ever held across a hostmap lookup.
This commit is contained in:
1 parent
d5062dacf0
commit
f9b0853476
8 files changed
+213
-27
No files matched your search
+9
-4
@@ -263,11 +263,16 @@ func (f *Interface) handleOutsideRelayPacket(hostinfo *HostInfo, via ViaSender,
|
||||
|
||||
// closeTunnel closes a tunnel locally, it does not send a closeTunnel packet to the remote
|
||||
func (f *Interface) closeTunnel(hostInfo *HostInfo) {
|
||||
final := f.hostMap.DeleteHostInfo(hostInfo)
|
||||
if final {
|
||||
// We no longer have any tunnels with this vpn addr, clear learned lighthouse state to lower memory usage
|
||||
f.lightHouse.DeleteVpnAddrs(hostInfo.vpnAddrs)
|
||||
// Hold the hostmap lock across both the delete and the lighthouse eviction,
|
||||
// to avoid a race with handshake completion.
|
||||
f.hostMap.Lock()
|
||||
defer f.hostMap.Unlock()
|
||||
if !f.hostMap.unlockedDeleteHostInfo(hostInfo) {
|
||||
return
|
||||
}
|
||||
|
||||
// We no longer have any tunnels with this vpn addr, clear learned lighthouse state to lower memory usage
|
||||
f.lightHouse.DeleteVpnAddrs(hostInfo.vpnAddrs)
|
||||
}
|
||||
|
||||
// sendCloseTunnel is a helper function to send a proper close tunnel packet to a remote
|
||||
|
||||
Reference in new issue
Block a user