Fix a race which causes the server unable to close all the connections in a session

This commit is contained in:
Qian Wang 2019-01-22 00:03:38 +00:00
parent 3a42ca5983
commit 9d2e9be1ef
1 changed files with 3 additions and 1 deletions

View File

@ -67,7 +67,7 @@ func (sb *switchboard) send(data []byte) (int, error) {
sb.txWait(n)
if sb.AddTxCredit(-int64(n)) < 0 {
log.Println(ErrNoTxCredit)
defer sb.session.Close()
go sb.session.Close()
return n, ErrNoTxCredit
}
atomic.AddUint32(&ce.sendQueue, ^uint32(n-1))
@ -119,9 +119,11 @@ func (sb *switchboard) removeConn(closing *connEnclave) {
// actively triggered by session.Close()
func (sb *switchboard) closeAll() {
sb.cesM.RLock()
for _, ce := range sb.ces {
ce.remoteConn.Close()
}
sb.cesM.RUnlock()
}
// deplex function costantly reads from a TCP connection, call deobfs and distribute it