Explorar el Código

Fix: for QUIC, treat NetworkIdleTimeout like PeerGoingAway

Rod Hynes hace 7 años
padre
commit
fb4f127d3d
Se han modificado 1 ficheros con 8 adiciones y 5 borrados
  1. 8 5
      psiphon/common/quic/quic.go

+ 8 - 5
psiphon/common/quic/quic.go

@@ -260,7 +260,7 @@ func (conn *Conn) Read(b []byte) (int, error) {
 	defer conn.readMutex.Unlock()
 
 	n, err := conn.stream.Read(b)
-	if isPeerGoingAway(err) {
+	if isErrorExpectedOnClose(err) {
 		err = io.EOF
 	}
 	return n, err
@@ -279,7 +279,7 @@ func (conn *Conn) Write(b []byte) (int, error) {
 	defer conn.writeMutex.Unlock()
 
 	n, err := conn.stream.Write(b)
-	if isPeerGoingAway(err) && n == len(b) {
+	if isErrorExpectedOnClose(err) && n == len(b) {
 		err = nil
 	}
 	return n, err
@@ -345,10 +345,13 @@ func (conn *Conn) SetWriteDeadline(t time.Time) error {
 	return conn.stream.SetWriteDeadline(t)
 }
 
-func isPeerGoingAway(err error) bool {
+func isErrorExpectedOnClose(err error) bool {
 	if err != nil {
-		if quicErr, ok := err.(*qerr.QuicError); ok && quicErr.ErrorCode == qerr.PeerGoingAway {
-			return true
+		if quicErr, ok := err.(*qerr.QuicError); ok {
+			switch quicErr.ErrorCode {
+			case qerr.PeerGoingAway, qerr.NetworkIdleTimeout:
+				return true
+			}
 		}
 	}
 	return false