From c335789e40a96fd29c41ee6d9dedab2eff9c9a5d Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 20 Feb 2018 21:22:41 +0100 Subject: [PATCH] close inner features before resetting --- dns.go | 2 ++ network.go | 11 +++++++++++ policy.go | 2 ++ router.go | 10 ++++++++++ 4 files changed, 25 insertions(+) diff --git a/dns.go b/dns.go index 5e94d1c2a..9a9b0c07d 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 d526a91f1..3b1b721a5 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 1ac9ac1fb..4cb9b3979 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 d3a8031f0..bd1e2d814 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()