Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
forks
ble
Commits
53fc7ac0
Unverified
Commit
53fc7ac0
authored
Mar 06, 2019
by
Eric Stutzenberger
Committed by
GitHub
Mar 06, 2019
Browse files
Merge pull request #4 from rigado/fix/race_on_disconnect
Fix race condition on disconnect
parents
0dba3c0c
579de926
Changes
2
Hide whitespace changes
Inline
Side-by-side
linux/hci/conn.go
View file @
53fc7ac0
...
...
@@ -195,6 +195,15 @@ func (c *Conn) writePDU(pdu []byte) (int, error) {
c
.
txBuffer
.
LockPool
()
defer
c
.
txBuffer
.
UnlockPool
()
// Fail immediately if the connection is already closed
// Check this with the pool locked to avoid race conditions
// with handleDisconnectionComplete
select
{
case
<-
c
.
chDone
:
return
0
,
io
.
ErrClosedPipe
default
:
}
for
len
(
pdu
)
>
0
{
// Get a buffer from our pre-allocated and flow-controlled pool.
pkt
:=
c
.
txBuffer
.
Get
()
// ACL pkt
...
...
linux/hci/hci.go
View file @
53fc7ac0
...
...
@@ -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 with the pool locked to avoid race conditions where
// writePDU is in progress and does a Get from the pool after this completes,
// leaking a buffer from the main pool.
c
.
txBuffer
.
LockPool
()
c
.
txBuffer
.
PutAll
()
c
.
txBuffer
.
UnlockPool
()
return
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment