diff --git a/dns.go b/dns.go index 5e94d1c2..9a9b0c07 100644 --- a/dns.go +++ b/dns.go @@ -52,6 +52,8 @@ func (d *syncDNSClient) Set(client DNSClient) { return } + d.Close() + d.Lock() defer d.Unlock() diff --git a/network.go b/network.go index d526a91f..3b1b721a 100644 --- a/network.go +++ b/network.go @@ -84,6 +84,12 @@ func (m *syncInboundHandlerManager) Close() error { } func (m *syncInboundHandlerManager) Set(manager InboundHandlerManager) { + if manager == nil { + return + } + + m.Close() + m.Lock() defer m.Unlock() @@ -161,6 +167,11 @@ func (m *syncOutboundHandlerManager) Close() error { } func (m *syncOutboundHandlerManager) Set(manager OutboundHandlerManager) { + if manager == nil { + return + } + + m.Close() m.Lock() defer m.Unlock() diff --git a/policy.go b/policy.go index 1ac9ac1f..4cb9b397 100644 --- a/policy.go +++ b/policy.go @@ -87,6 +87,8 @@ func (m *syncPolicyManager) Set(manager PolicyManager) { return } + m.Close() + m.Lock() defer m.Unlock() diff --git a/router.go b/router.go index d3a8031f..bd1e2d81 100644 --- a/router.go +++ b/router.go @@ -54,6 +54,11 @@ func (d *syncDispatcher) Close() error { } func (d *syncDispatcher) Set(disp Dispatcher) { + if disp == nil { + return + } + + d.Close() d.Lock() defer d.Unlock() @@ -108,6 +113,11 @@ func (r *syncRouter) Close() error { } func (r *syncRouter) Set(router Router) { + if router == nil { + return + } + + r.Close() r.Lock() defer r.Unlock()