From f936151f2dc0de0caed3950c3c3d7f43959db21c Mon Sep 17 00:00:00 2001 From: Arceliar Date: Tue, 22 Jan 2019 21:48:43 -0600 Subject: [PATCH] correctly clean up various things --- src/yggdrasil/link.go | 12 ++++++++++-- src/yggdrasil/tcp.go | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/yggdrasil/link.go b/src/yggdrasil/link.go index 0953e4f..660c854 100644 --- a/src/yggdrasil/link.go +++ b/src/yggdrasil/link.go @@ -114,7 +114,12 @@ func (intf *linkInterface) handler() error { } else { intf.closed = make(chan struct{}) intf.link.interfaces[intf.info] = intf - defer close(intf.closed) + defer func() { + intf.link.mutex.Lock() + delete(intf.link.interfaces, intf.info) + intf.link.mutex.Unlock() + close(intf.closed) + }() intf.link.core.log.Println("DEBUG: registered interface for", intf.name) } intf.link.mutex.Unlock() @@ -144,7 +149,10 @@ func (intf *linkInterface) handler() error { timer := time.NewTimer(interval) clearTimer := func() { if !timer.Stop() { - <-timer.C + select { + case <-timer.C: + default: + } } } defer clearTimer() diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index 09ed7d0..e1f490e 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -294,8 +294,8 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) { panic(err) } iface.core.log.Println("DEBUG: starting handler for", name) - link.handler() - iface.core.log.Println("DEBUG: stopped handler for", name) + err = link.handler() + iface.core.log.Println("DEBUG: stopped handler for", name, err) } // This exchanges/checks connection metadata, sets up the peer struct, sets up the writer goroutine, and then runs the reader within the current goroutine.