Skip to content

Commit

Permalink
fix: resolve the data race of stdConn on Windows (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Verthandii committed Jul 24, 2021
1 parent b95d9db commit 990db79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions acceptor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func (svr *server) listenerRun(lockOSThread bool) {
go func() {
var buffer [0x10000]byte
for {
n, err := c.conn.Read(buffer[:])
n, err := conn.Read(buffer[:])
if err != nil {
_ = c.conn.SetReadDeadline(time.Time{})
_ = conn.SetReadDeadline(time.Time{})
el.ch <- &stderr{c, err}
return
}
Expand Down
2 changes: 2 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var (
ErrUnsupportedUDSProtocol = errors.New("only unix is supported")
// ErrUnsupportedPlatform occurs when running gnet on an unsupported platform.
ErrUnsupportedPlatform = errors.New("unsupported platform in gnet")
// ErrConnectionClosed occurs when the event-loop receives a closed connection.
ErrConnectionClosed = errors.New("connection is closed")

// ================================================= codec errors =================================================.

Expand Down
6 changes: 5 additions & 1 deletion eventloop_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (el *eventloop) loopRun(lockOSThread bool) {
case *stdConn:
err = el.loopAccept(v)
case *tcpConn:
if v.c.conn == nil {
err = errors.ErrConnectionClosed
break
}
v.c.buffer = v.bb
err = el.loopRead(v.c)
case *udpConn:
Expand All @@ -102,7 +106,7 @@ func (el *eventloop) loopRun(lockOSThread bool) {
el.getLogger().Debugf("event-loop(%d) is exiting in terms of the demand from user, %v", el.idx, err)
break
} else if err != nil {
el.getLogger().Errorf("event-loop(%d) is exiting due to the error: %v", el.idx, err)
el.getLogger().Debugf("event-loop(%d) got a nonlethal error: %v", el.idx, err)
}
}
}
Expand Down

0 comments on commit 990db79

Please sign in to comment.