Skip to content

Commit 713a871

Browse files
author
Vito Caputo
committed
Prevent double-close panic in conn.Close
inWorker calls Conn.Close() following a read error. The read error may be caused by an external caller calling Conn.Close() in an active close of the established connection. Only one of the callers shall be permitted to perform the actual closing. We're already maintaining a synchronized closed state in Conn.closed, simply short-circuit Conn.Close() when Conn.closed == true.
1 parent cfab99a commit 713a871

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

conn.go

+7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ func (conn *Conn) BusObject() *Object {
175175
// not be called on shared connections.
176176
func (conn *Conn) Close() error {
177177
conn.outLck.Lock()
178+
if conn.closed {
179+
// inWorker calls Close on read error, the read error may
180+
// be caused by another caller calling Close to shutdown the
181+
// dbus connection, a double-close scenario we prevent here.
182+
conn.outLck.Unlock()
183+
return nil
184+
}
178185
close(conn.out)
179186
conn.closed = true
180187
conn.outLck.Unlock()

0 commit comments

Comments
 (0)