From 4fba5586380b59ba063fd5adaded1dec7c6f9cbf Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 16 Jan 2019 13:20:12 +0000 Subject: [PATCH] Fix concurrent map write in tcp.go --- src/yggdrasil/tcp.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index c90c3ff..1ebf0b6 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -125,8 +125,10 @@ func (iface *tcpInterface) listen() error { } iface.serv, err = lc.Listen(ctx, "tcp", iface.tcp_addr) if err == nil { + iface.mutex.Lock() iface.calls = make(map[string]struct{}) iface.conns = make(map[tcpInfo](chan struct{})) + iface.mutex.Unlock() go iface.listener() return nil } @@ -187,7 +189,9 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string, sintf string) { if iface.isAlreadyCalling(saddr) { return } + iface.mutex.Lock() iface.calls[callname] = struct{}{} + iface.mutex.Unlock() defer func() { // Block new calls for a little while, to mitigate livelock scenarios time.Sleep(default_tcp_timeout)