Skip to content

Commit

Permalink
fix: connection leak when poller close connection but onRequest callb…
Browse files Browse the repository at this point in the history
…ack just finished
  • Loading branch information
joway committed Jan 31, 2024
1 parent 329188d commit edd4e8f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 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,14 @@ 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 {
// must be closed by poller, so no need to detach
c.closeCallback(false, false)
}
// double check isProcessable
if isProcessable(c) && c.lock(processing) {
goto START
}
Expand Down

0 comments on commit edd4e8f

Please sign in to comment.