Commit 19fcd8a2 authored by Jeff Lassahn's avatar Jeff Lassahn
Browse files

Fix race condition where new data can be written to a connection while it

is being disconnected, and the buffers are leaked from the packet pool
parent 0dba3c0c
......@@ -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 wwith 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