Fix race condition on disconnect #4
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The library can write new data to a connection while it is being disconnected, and the buffers used for that data are leaked from the packet pool forever. This can happen invisibly even if the application isn't sending data, e.g. when a Connection Parameter Update Request comes in and the library automatically generates a response.
The fix checks for a closed connection before writing data, and both the check and the final packet pool update are done while holding the packet pool lock. This guarantees the final pool drain for the closed connection happens after any writes on the connection are complete.