From 9d2e9be1ef46c76c2ca81d0793ffc47820dead7c Mon Sep 17 00:00:00 2001 From: Qian Wang Date: Tue, 22 Jan 2019 00:03:38 +0000 Subject: [PATCH] Fix a race which causes the server unable to close all the connections in a session --- internal/multiplex/switchboard.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/multiplex/switchboard.go b/internal/multiplex/switchboard.go index ad1720a..0bb13a1 100644 --- a/internal/multiplex/switchboard.go +++ b/internal/multiplex/switchboard.go @@ -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