While hacking a little bit with GConf I found what IMHO is an undesirable behaviour of GConf. I think most of developers will agree because you don’t want your application to run in a different way than the one you expected when you designed it. And this happens in the following situation:

I set up a GConfClient to listen to changes in keys under a specific directory. I wrote also a handler for this GConf notifications hoping that I’ll get every change in those keys (the API doc literally says “Any changes to keys below this directory will cause the “value_changed” signal to be emitted”). So I relied in this GConf notification handler some important code of my application. But, while executing the application I realized that I was not getting some notifications even tough I was completely sure that I was setting a new value in the GConf key. So, I had to take a deeper look…

I verified that the GConf server was issuing a notification for every change I made, so the problem should be in the client. Looking at the GConfClient code I found the following in the notify_from_server_callback function:

changed = gconf_client_cache (client, FALSE, entry, TRUE);

if (!changed)
return; /* don't do the notify */

gconf_client_queue_notify (client, entry->key);

What? This means that I won’t get notifications if the key is already updated in the client cache? What’s the reason for such a behaviour? I don’t think this is what a developer expects, specially for a system that uses idles for notifications (you could never be sure when you’ll get it), because it could cause things like the one that was happening to me:

  • As a response to a user action I was setting a new value to a GConf key
  • Before the GConfServer notified the GConfClient, there was some other code that was trying to get the new value of the same key
  • GConf cached the new value in the client while doing the get operation
  • The GConfClient received the GConfServer notification, but was not issuing a notification because the value was already updated
  • I was scratching my head trying to figure out what the hell was happening … 😀

So, IMHO there are two possibilities

  1. Always notify
  2. Write in bold 46-point sized font that sometimes you could not get notifications because of that

Anyway, it’s always good to look into the guts of the software you use.