8000 Fix race condition on disconnect by jlassahnrigado · Pull Request #4 · rigado/ble · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix race condition on disconnect #4

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

Merged
merged 2 commits into from
Mar 6, 2019
Merged

Conversation

jlassahnrigado
Copy link
Contributor

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.

…e it

is being disconnected, and the buffers are leaked from the packet pool
forever.
Copy link
Contributor
@estutzenberger estutzenberger left a comment

Choose a reason for hiding this comment

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

Looks good, just a typo

linux/hci/hci.go Outdated
@@ -513,7 +513,13 @@ func (h *HCI) handleDisconnectionComplete(b []byte) error {
}
// When a connection disconnects, all the sent packets and weren't acked yet
// will be recycled. [Vol2, Part E 4.1.1]
//
// must be done wwith the pool locked to avoid race conditions where
Copy link
Contributor

Choose a reason for hiding this comment

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

wwith -> with

@estutzenberger estutzenberger merged commit 53fc7ac into master Mar 6, 2019
@jlassahnrigado jlassahnrigado deleted the fix/race_on_disconnect branch June 6, 2019 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0