mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-01 17:49:02 +00:00
net/tsdial: do not panic if setting the same eventbus twice (#17640)
Updates #17638
Signed-off-by: Claus Lensbøl <claus@tailscale.com>
(cherry picked from commit fd0e541e5d)
This commit is contained in:
@@ -96,6 +96,7 @@ type Dialer struct {
|
||||
dnsCache *dnscache.MessageCache // nil until first non-empty SetExitDNSDoH
|
||||
nextSysConnID int
|
||||
activeSysConns map[int]net.Conn // active connections not yet closed
|
||||
bus *eventbus.Bus // only used for comparison with already set bus.
|
||||
eventClient *eventbus.Client
|
||||
eventBusSubs eventbus.Monitor
|
||||
}
|
||||
@@ -226,14 +227,17 @@ func (d *Dialer) NetMon() *netmon.Monitor {
|
||||
func (d *Dialer) SetBus(bus *eventbus.Bus) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
if d.eventClient != nil {
|
||||
panic("eventbus has already been set")
|
||||
if d.bus == bus {
|
||||
return
|
||||
} else if d.bus != nil {
|
||||
panic("different eventbus has already been set")
|
||||
}
|
||||
// Having multiple watchers could lead to problems,
|
||||
// so unregister the callback if it exists.
|
||||
if d.netMonUnregister != nil {
|
||||
d.netMonUnregister()
|
||||
}
|
||||
d.bus = bus
|
||||
d.eventClient = bus.Client("tsdial.Dialer")
|
||||
d.eventBusSubs = d.eventClient.Monitor(d.linkChangeWatcher(d.eventClient))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user