Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: read goroutine nil pointer panic #235

Merged
merged 7 commits into from
Jul 24, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 connection is closed but eventloop.ch still receive this connection.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成 "ErrConnectionClosed occurs when the event-loop receives a closed connection."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

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 {
panjf2000 marked this conversation as resolved.
Show resolved Hide resolved
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