5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-23 07:35:39 +00:00

Fix concurrent map write in tcp.go

This commit is contained in:
Neil Alexander 2019-01-16 13:20:12 +00:00
parent 8fa9b84108
commit 4fba558638
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -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)