Browse Source

QUIC optimization

When Read or Write encounters a terminal connection error (PeerGoingAway or
NetworkIdleTimeout), call Close; this results in IsClosed being true when a
QUIC-OSSH tunnel operator checks its status after a terminal error, bypassing
any keep alive probe delay.
Rod Hynes 7 years ago
parent
commit
f70264cf4f
1 changed files with 8 additions and 4 deletions
  1. 8 4
      psiphon/common/quic/quic.go

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

@@ -260,7 +260,8 @@ func (conn *Conn) Read(b []byte) (int, error) {
 	defer conn.readMutex.Unlock()
 
 	n, err := conn.stream.Read(b)
-	if isErrorExpectedOnClose(err) {
+	if isErrorIndicatingClosed(err) {
+		_ = conn.Close()
 		err = io.EOF
 	}
 	return n, err
@@ -279,8 +280,11 @@ func (conn *Conn) Write(b []byte) (int, error) {
 	defer conn.writeMutex.Unlock()
 
 	n, err := conn.stream.Write(b)
-	if isErrorExpectedOnClose(err) && n == len(b) {
-		err = nil
+	if isErrorIndicatingClosed(err) {
+		_ = conn.Close()
+		if n == len(b) {
+			err = nil
+		}
 	}
 	return n, err
 }
@@ -345,7 +349,7 @@ func (conn *Conn) SetWriteDeadline(t time.Time) error {
 	return conn.stream.SetWriteDeadline(t)
 }
 
-func isErrorExpectedOnClose(err error) bool {
+func isErrorIndicatingClosed(err error) bool {
 	if err != nil {
 		if quicErr, ok := err.(*qerr.QuicError); ok {
 			switch quicErr.ErrorCode {