[Solved] D-Bus Method Call Stops Working After Few Days

D-Bus diagramD-Bus diagram

This is an issue that I've found some months ago. I've set up a communication system using asynchronous calls made with D-Bus. It all seemed to work fine for a couple of days but suddenly the entire mechanism stopped working with no errors reported.

I've searched around if there was a known bug or if someone else was having the same issue but without result. For this reason I write here the solution, hoping this can be useful for other developers.

The Situation

This is the sequence:

  1. create a new method call
  2. append the parameters
  3. send it
  4. free the memory.

Or, if you prefer the code:

DBusMessage *msg = dbus_message_new_method_call(dest, path, iface, method);  
        DBUS_TYPE_UINT32,  &int_par,
        DBUS_TYPE_STRING,  &string_par,
        DBUS_TYPE_INVALID  // closes the function parameters
dbus_connection_send(bus, msg, NULL);  

Quite linear, isn't it? Unfortunately after a while (I've estimated after 50.000/100.000 calls) the wanted method is no more called but no error is returned when the message is sent.

The Solution

My assumption was that some kind of memory limit was reached, so I've read the documentation carefully and I've found the following function:

dbus_message_set_no_reply(msg, TRUE);  

Adding it before dbus_connection_send() made the whole system run for weeks without any problem.

Luca Sommacal

Luca Sommacal

Italian developer (mainly in C for embedded platforms), Linux learner, addicted to rock music, history, science and few other things. Follow me on Twitter

comments powered by Disqus