guelfey / go.dbus

Native Go bindings for D-Bus
BSD 2-Clause "Simplified" License
124 stars 42 forks source link

conn.Close() may lose outbound messages #57

Open aulanov opened 9 years ago

aulanov commented 9 years ago

Consider the following code that tries to send a signal:

        conn, err := dbus.SystemBusPrivate()
        conn.Auth(nil)
        conn.Hello()
        conn.RequestName(objName, dbus.NameFlagDoNotQueue)
        conn.Emit(objPath, signalName, "")
        conn.Close()
        os.Exit(0)

Even though the code itself looks correct most likely it will not send any signals. Here Emit() does not actually send a message to the bus, it just queues the message to be sent by a separate goroutine. But there is no guarantee that the message will be sent before program terminates.

conn.Close() closes dbus connection but does not synchronize with outWorker(). Out channel may or may not be empty after Close() and so messages may or may not be sent.

The suggested solution is to add synchronization between Close() and outWorker() so that Close() awaits termination of outWorker() and so guarantees that all outbound signals as well as NoReplyExpected calls are sent to the bus.