mirror of https://github.com/cbeuw/Cloak
Code style changes and unlock mutex when failed to open stream
This commit is contained in:
parent
a26a2e84a4
commit
e3ba82caac
|
|
@ -46,13 +46,14 @@ func RouteUDP(bindFunc func() (*net.UDPConn, error), streamTimeout time.Duration
|
||||||
sesh.Close()
|
sesh.Close()
|
||||||
}
|
}
|
||||||
log.Errorf("Failed to open stream: %v", err)
|
log.Errorf("Failed to open stream: %v", err)
|
||||||
|
streamsMutex.Unlock()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_ = stream.SetReadDeadline(time.Now().Add(streamTimeout))
|
|
||||||
|
|
||||||
streams[addr.String()] = stream
|
streams[addr.String()] = stream
|
||||||
streamsMutex.Unlock()
|
streamsMutex.Unlock()
|
||||||
|
|
||||||
|
_ = stream.SetReadDeadline(time.Now().Add(streamTimeout))
|
||||||
|
|
||||||
proxyAddr := addr
|
proxyAddr := addr
|
||||||
go func(stream *mux.Stream, localConn *net.UDPConn) {
|
go func(stream *mux.Stream, localConn *net.UDPConn) {
|
||||||
buf := make([]byte, 8192)
|
buf := make([]byte, 8192)
|
||||||
|
|
@ -60,24 +61,21 @@ func RouteUDP(bindFunc func() (*net.UDPConn, error), streamTimeout time.Duration
|
||||||
n, err := stream.Read(buf)
|
n, err := stream.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Tracef("copying stream to proxy client: %v", err)
|
log.Tracef("copying stream to proxy client: %v", err)
|
||||||
streamsMutex.Lock()
|
break
|
||||||
delete(streams, addr.String())
|
|
||||||
streamsMutex.Unlock()
|
|
||||||
stream.Close()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
_ = stream.SetReadDeadline(time.Now().Add(streamTimeout))
|
_ = stream.SetReadDeadline(time.Now().Add(streamTimeout))
|
||||||
|
|
||||||
_, err = localConn.WriteTo(buf[:n], proxyAddr)
|
_, err = localConn.WriteTo(buf[:n], proxyAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Tracef("copying stream to proxy client: %v", err)
|
log.Tracef("copying stream to proxy client: %v", err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
streamsMutex.Lock()
|
streamsMutex.Lock()
|
||||||
delete(streams, addr.String())
|
delete(streams, addr.String())
|
||||||
streamsMutex.Unlock()
|
streamsMutex.Unlock()
|
||||||
stream.Close()
|
stream.Close()
|
||||||
return
|
return
|
||||||
}
|
|
||||||
}
|
|
||||||
}(stream, localConn)
|
}(stream, localConn)
|
||||||
} else {
|
} else {
|
||||||
streamsMutex.Unlock()
|
streamsMutex.Unlock()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue