فهرست منبع

Add is-closed checks to WebRTCConn Read/Write to ensure fast fail when closed

Rod Hynes 1 سال پیش
والد
کامیت
c11fd514ea
1فایلهای تغییر یافته به همراه11 افزوده شده و 2 حذف شده
  1. 11 2
      psiphon/common/inproxy/webrtc.go

+ 11 - 2
psiphon/common/inproxy/webrtc.go

@@ -798,12 +798,17 @@ func (conn *WebRTCConn) readMessage(p []byte) (int, error) {
 
 
 	// Don't hold this lock, or else concurrent Writes will be blocked.
 	// Don't hold this lock, or else concurrent Writes will be blocked.
 	conn.mutex.Lock()
 	conn.mutex.Lock()
+	isClosed := conn.isClosed
 	dataChannelConn := conn.dataChannelConn
 	dataChannelConn := conn.dataChannelConn
 	decoyDone := conn.decoyDone
 	decoyDone := conn.decoyDone
 	conn.mutex.Unlock()
 	conn.mutex.Unlock()
 
 
+	if isClosed {
+		return 0, errors.TraceNew("closed")
+	}
+
 	if dataChannelConn == nil {
 	if dataChannelConn == nil {
-		return 0, errors.TraceNew("not connected")
+		return 0, errors.TraceNew("no data channel")
 	}
 	}
 
 
 	// The input read buffer, p, may not be the same length as the message
 	// The input read buffer, p, may not be the same length as the message
@@ -910,8 +915,12 @@ func (conn *WebRTCConn) writeMessage(p []byte, decoy bool) (int, error) {
 	dataChannelConn := conn.dataChannelConn
 	dataChannelConn := conn.dataChannelConn
 	conn.mutex.Unlock()
 	conn.mutex.Unlock()
 
 
+	if isClosed {
+		return 0, errors.TraceNew("closed")
+	}
+
 	if dataChannelConn == nil {
 	if dataChannelConn == nil {
-		return 0, errors.TraceNew("not connected")
+		return 0, errors.TraceNew("no data channel")
 	}
 	}
 
 
 	// Only proceed with a decoy message when no pending writes are buffered.
 	// Only proceed with a decoy message when no pending writes are buffered.