Unverified Commit 53fc7ac0 authored by Eric Stutzenberger's avatar Eric Stutzenberger Committed by GitHub
Browse files

Merge pull request #4 from rigado/fix/race_on_disconnect

Fix race condition on disconnect
parents 0dba3c0c 579de926
......@@ -195,6 +195,15 @@ func (c *Conn) writePDU(pdu []byte) (int, error) {
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
for len(pdu) > 0 {
// Get a buffer from our pre-allocated and flow-controlled pool.
pkt := c.txBuffer.Get() // ACL pkt
......@@ -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.
return nil
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment