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: connection leak when poller close connection but onRequest callback just finished #304

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Changes from all 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
14 changes: 12 additions & 2 deletions connection_onevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (c *connection) onProcess(isProcessable func(c *connection) bool, process f
}
process(c)
}
// Handling callback if connection has been closed.
// handling callback if connection has been closed.
if closedBy != none {
// if closed by user when processing, it "may" needs detach
needDetach := closedBy == user
Expand All @@ -223,7 +223,17 @@ func (c *connection) onProcess(isProcessable func(c *connection) bool, process f
return
}
c.unlock(processing)
// Double check when exiting.
// Note: Poller's closeCallback call will try to get processing lock failed but here already neer to unlock processing.
// So here we need to check connection state again, to avoid connection leak
// double check close state
if c.status(closing) != 0 && c.lock(processing) {
ppzqh marked this conversation as resolved.
Show resolved Hide resolved
// poller will get the processing lock failed, here help poller do closeCallback
// fd must already detach by poller
c.closeCallback(false, false)
panicked = false
return
}
// double check isProcessable
if isProcessable(c) && c.lock(processing) {
goto START
}
Expand Down
Loading