From 1d1c6efa1fab9d444bfdfe40cf9bdd50216a4942 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sun, 18 Oct 2020 11:01:18 -0500 Subject: [PATCH] attempt to keep TCP listener alive if there's a temporary error (e.g. too many open files), just pause and retry later --- src/multicast/multicast.go | 4 +++- src/yggdrasil/tcp.go | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/multicast/multicast.go b/src/multicast/multicast.go index 33cb29ab..430e9374 100644 --- a/src/multicast/multicast.go +++ b/src/multicast/multicast.go @@ -191,7 +191,9 @@ func (m *Multicast) getAllowedInterfaces() map[string]net.Interface { // Ask the system for network interfaces allifaces, err := net.Interfaces() if err != nil { - panic(err) + // Don't panic, since this may be from e.g. too many open files (from too much connection spam) + // TODO? log something + return nil } // Work out which interfaces to announce on for _, iface := range allifaces { diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index 15d70470..ad9d872e 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -226,7 +226,13 @@ func (t *tcp) listener(l *TcpListener, listenaddr string) { sock, err := l.Listener.Accept() if err != nil { t.links.core.log.Errorln("Failed to accept connection:", err) - return + select { + case <-l.stop: + return + default: + } + time.Sleep(time.Second) // So we don't busy loop + continue } t.waitgroup.Add(1) options := tcpOptions{