diff --git a/netconn.go b/netconn.go index 34f771c6d1a84429822aa7eb72569cc32a6ed120..c5c0e17b3171bda9c5f11ff298db9248ef024c61 100644 --- a/netconn.go +++ b/netconn.go @@ -7,6 +7,7 @@ import ( "io" "math" "net" + "sync" "sync/atomic" "time" ) @@ -69,8 +70,9 @@ type netConn struct { readTimer *time.Timer readContext context.Context - eofed bool + readMu sync.Mutex + eofed bool reader io.Reader } @@ -89,6 +91,9 @@ func (c *netConn) Write(p []byte) (int, error) { } func (c *netConn) Read(p []byte) (int, error) { + c.readMu.Lock() + defer c.readMu.Unlock() + if c.eofed { return 0, io.EOF }