Handling message replies asynchronously in a separate thread produces a warning

Havoc Pennington hp at redhat.com
Fri Nov 25 19:26:03 PST 2005


On Fri, 2005-11-25 at 12:52 +0000, Jamie McCracken wrote:
> I am being a bit naughty as the message handling func will return 
> DBUS_HANDLER_RESULT_HANDLED even though the actual reply will be sent 
> back much later on in a different thread (there is no way round this for 
> me as its the only way to create a fast stateless multithreaded 
> middleware server)

should be fine afaik

> The warning relates to calling dbus_message_ref (message) which I need 
> to do to keep the message alive after the message handler function has 
> exited and until its processed later on.
> 
> The warning happens very rarely and is as follows :
> 
> 10308: arguments to dbus_message_ref() were incorrect, assertion 
> "!message->in_cache" failed in file dbus-message.c line 1083.

That warning would normally mean that you are ref'ing a message that's
been finalized. Why it's been finalized I have no idea, valgrind would
be one good way to debug it (you may need to turn off the message cache
stuff in dbus-message.c so we really free() the message and valgrind
will complain)

> By calling dbus_message_ref (message) earlier on in the function the 
> warning seems to disappear or occur less likely - why?.

Just the usual unpredictable nature of threads I imagine. Race
conditions are by definition unpredictable, no?

libdbus is not heavily tested in threaded programs; you will need to be
prepared to dig into it and do some debugging.

Havoc





More information about the dbus mailing list