[java] dbus disconnecting / threaded use of dbus

Colby M White colby.white at utexas.edu
Thu Sep 6 09:54:42 PDT 2012

Thanks for the responses.

Everything I can see indicates the messages are UTF-8 and thus the messages
are legit. That wouldn't explain why sometimes it works and sometimes it
fails though.

I put the debug on all, but it's logging the bytes of the messages. Looking
at that, I can't really tell if the messages are off.

One detail I left out is the Observable/Observer pattern I'm using. The
Observer implements my DBusInterface and exports itself to the dbus. The
Observable is a thread that runs and updates its state every so often. When
the Observable updates, the DbusObserver gets the update and emits a signal
to the dbus. Is this perhaps a bad design? Could having N Observers
accessing the dbus be an issue? (I'm guessing no since the dbus library
appears thread-safe. I'm somewhat grasping at straws now.)

I went ahead and tried to create a small project to demonstrate the issue
(mostly for myself). Again, sometimes it fails, sometimes it doesn't.
Sometimes it takes a while to fail. If anyone somehow has the time/desire
to dive into it, https://www.dropbox.com/s/ffbjp24h58s1yg3/dbus-test.tar.gz

Colby M. White

On Tue, Sep 4, 2012 at 6:07 PM, Matthew Johnson <dbus at matthew.ath.cx> wrote:

> On Tue Sep 04 11:40, Colby M White wrote:
> > I am attempting to use the java bindings for dbus and am encountering a
> > disconnecting problem. When I send a signal, the connection is
> disconnected
> > with out given me much of a reason as to why. Part of the issue is it
> > doesn't happen all the time, just when it feels like it. That's making it
> > hard to reproduce.
> Hi, that's really strange - it definitely shouldn't do that.
> > So my main question: What are the possible reasons that a connection
> would
> > decide to disconnect (other then hitting the DBusConnection.disconnect()
> > method, which I confirmed is never being called in my code)? If I knew
> what
> > could cause a disconnection, then it would narrow my search.
> Generally sending malformed stuff. Aside from strings I really should be
> stopping you sending anything illegal though.
> > One unique aspect to my setup is that I'm sending multiple signals, each
> by
> > its own thread. As far as I can tell, I've done this in a thread-safe
> > manner. When the signals are sent, they are sent in a synchronized block.
> > Here's a quick stream-lined glance at my class (Topic is a basic
> > DBusInterface that only has a signal):
> it should already be thread-safe. Sending any message just appends it to a
> queue, which a background thread pops from and does the actual send.
> >
> > Is there something about using this java binding in a threaded
> environment
> > that I'm missing? Are there some dbus-thread guidelines/safe practices?
> I'm
> > not entirely sure my threaded environment and the disconnections are
> > related (or at least my tests aren't showing that they are), but the very
> > nature of threads makes it hard to know. My gut tells me they probably
> are
> > related.
> Nothing in that snippet looks obvious. Do you have a testcase you can
> reproduce
> with?
> > I recompiled my dbus jar with debug enabled and here is what is happening
> > after I send the signal. As you can see it writes, then disconnects right
> > after.
> >
> > [org.freedesktop.dbus.AbstractConnection$_sender.run()] Got message:
> > DataChanged(0,7) { Path=>..., Interface=>dbus.topics.Topic,
> > Member=>DataChanged, Signature=>a{sv} } { { //the contents of my map//} }
> > [org.freedesktop.dbus.Message.append()] Appending sig: a{sv} data: [{
> //the
> > contents of my map//}]
> > [org.freedesktop.dbus.MessageWriter.writeMessage()] <= DataChanged(0,7) {
> > Path=>..., Interface=>dbus.topics.Topic, Member=>DataChanged,
> > Signature=>a{sv} } { { //the contents of my map//} }
> > [org.freedesktop.dbus.MessageWriter.writeMessage()] Writing all 102
> buffers
> > simultaneously to Unix Socket
> > [org.freedesktop.dbus.DBusConnection.disconnect()] Disconnecting
> > DBusConnection
> >
> > Any help on dbus disconnections and/or how to get it to tell me why it is
> > disconnecting would be helpful.
> Can you try changing the log levels by adding a debug.conf in the working
> directory? Try:
> org.freedesktop.dbus.MessageWriter=VERBOSE
> or (warning, lots of output) ALL=VERBOSE
> Matt
> Version: GnuPG v1.4.9 (GNU/Linux)
> hGHRa5p208bnI9ND3GGt2QNzXA1evCy15CoLIsurMQUlDrqV+uu6OnUelGkkk4da
> R8enExKwRI94xssdYzb47n8DQBsxxG6Chmu8z9KCUFSlECFGivMwCyt5ptDRvWMv
> mxN0O6D8LOMsOusm7bA9ceUELYK6B+mtE2UT7yqVvlbnw3U18DtqK7naGx/UwEdL
> zTpWC00W7gpaBP3f6OPDUcCuOPycvNlv5hNcFgbgSes7rskRCcnk2zOXkX0/MudM
> cJ4URSVuDvQWGJsdwNs2WW7d0lSHRKvNBfnK289hvr7mpgnIui1v3y+HpX+9epW8
> QwAboaKNF/1a3xkxtiClshpZBLDkEsd5oyUOu6H0qOisTEHq+xaXJnXEePa0Y7Vs
> +5uPzhLKx9Sc2yBwGrVrwA8mTHA+tdC7l5Wwr4JxblR7g0Yv1IQd/xl30SUWd4Cl
> fo1T17YgC9CnZzrjEaUHPDu8/cD/QNx8HciOI5EbX+slVx0DCYjjA7ZybzqlTMz7
> sXdiqE0GhWg17i4biE6/+2iPKn7PXDoUQqPJIrjW0qfN911etebBFkVtugGoeQ8C
> ltNqWFYpK09jX2XK1QzOrj4EAsHtg0jC8pZEm2G3/rkFlY2xmDX4SSfyDWAOcy1m
> AJsxwJQbkoMiNmzv1Qyz
> =ijnA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20120906/23d60cdc/attachment.html>

More information about the dbus mailing list