mirror of https://github.com/cbeuw/Cloak
Fix potential deadlocks
This commit is contained in:
parent
dd61c35356
commit
c9318dc90b
|
|
@ -56,6 +56,7 @@ type Session struct {
|
||||||
// Switchboard manages all connections to remote
|
// Switchboard manages all connections to remote
|
||||||
sb *switchboard
|
sb *switchboard
|
||||||
|
|
||||||
|
// Used for LocalAddr() and RemoteAddr() etc.
|
||||||
addrs atomic.Value
|
addrs atomic.Value
|
||||||
|
|
||||||
// For accepting new streams
|
// For accepting new streams
|
||||||
|
|
@ -150,8 +151,8 @@ func (sesh *Session) recvDataFromRemote(data []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
sesh.streamsM.Lock()
|
sesh.streamsM.Lock()
|
||||||
defer sesh.streamsM.Unlock()
|
|
||||||
stream, existing := sesh.streams[frame.StreamID]
|
stream, existing := sesh.streams[frame.StreamID]
|
||||||
|
sesh.streamsM.Unlock()
|
||||||
if existing {
|
if existing {
|
||||||
return stream.writeFrame(*frame)
|
return stream.writeFrame(*frame)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,9 @@ func (s *Stream) Write(in []byte) (n int, err error) {
|
||||||
n, err = s.session.sb.send(s.obfsBuf[:i], &s.assignedConnId)
|
n, err = s.session.sb.send(s.obfsBuf[:i], &s.assignedConnId)
|
||||||
log.Tracef("%v sent to remote through stream %v with err %v", len(in), s.id, err)
|
log.Tracef("%v sent to remote through stream %v with err %v", len(in), s.id, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == errBrokenSwitchboard {
|
||||||
|
s.session.Close()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return len(in), nil
|
return len(in), nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue