Browse Source

Fix: loop and read again when 0 bytes are read with no error

Rod Hynes 7 years ago
parent
commit
fb94cfa4f5
1 changed files with 8 additions and 0 deletions
  1. 8 0
      psiphon/common/tun/nonblock.go

+ 8 - 0
psiphon/common/tun/nonblock.go

@@ -128,6 +128,14 @@ func (nio *NonblockingIO) Read(p []byte) (int, error) {
 		if err != nil && err != io.EOF {
 		if err != nil && err != io.EOF {
 			return n, common.ContextError(err)
 			return n, common.ContextError(err)
 		}
 		}
+
+		if n == 0 && err == nil {
+			// https://godoc.org/io#Reader:
+			// "Implementations of Read are discouraged from
+			// returning a zero byte count with a nil error".
+			continue
+		}
+
 		return n, err
 		return n, err
 	}
 	}
 }
 }