Register a Service will block the overall DBus usage
There seems to be an error accessing a remote DBus object (e.g. from BlueZ) when a local Service was registered at the same time / session.
The following example shows the error. The error could be turned on and off by toggeling in/out line 14.
var DBus = require('dbus');
var BluezDBusPathPrefix = '/';
var BluezUri = 'org.bluez';
var DBusUriObjectManager = 'org.freedesktop.DBus.ObjectManager';
var dbusSystem = DBus.getBus('system');
// We want to register our own service.
// This could be done by using the following line
// Nevertheless, this line seems to block the further usage of DBus.
// So the 'getInterface' call (see below) wont return successfully
var dbusService = DBus.registerService('system', 'org.example.something');
dbusSystem.getInterface(
BluezUri,
BluezDBusPathPrefix,
DBusUriObjectManager,
function(err, obj) {
console.log("ObjectManager callback called");
if (err || !obj) {
console.log("Failed to get Object Manager: " + err);
return;
}
obj.GetManagedObjects({ timeout: 1000 }, function(err, objects) {
if (err) {
console.log(err);
return;
}
console.log("GetManagedObjects callback received");
for (var path in objects) {
for (var iface in objects[path]) {
console.log("Object with path='"+path+"' and iface='"+iface+"'")
}
}
});
obj.on('InterfacesAdded', function(a,b) {console.log('InterfacesAdded');});
obj.on('InterfacesRemoved', function(a,b) {console.log('InterfacesRemoved');});
});
What happens when you change line 14 to register on 'session' instead of 'system'? E.g.
var dbusService = DBus.registerService('service', 'org.example.something');
Does it work then? I used similar code (except I don't have Bluez, so I connected to a different interface), and I could reproduce the issue when trying to register an object in the system bus, but succeeded when registering an object in the session bus.
It it does work in that situation, it's probably more of a permissions issue (DBus is strict on permissions on the system bus, lax on permissions on the session bus) than an issue with this library.
I have had similar issue and I worked around it by creating only one dbus system bus object. So in your example you can remove the line:
var dbusSystem = DBus.getBus('system');
and place following line after registering service:
var dbusSystem = dbusService.bus;
Hi! Thanks for your help. At the moment I don't need a workaround as far as we have switched to Python instead. Nevertheless, this is just a bug report and I think it is a valid bug report. So I understand the second workaround but what would happen on multiple services that will be created during runtime, after the DBus session is already in use? So this workaround is only for my simple example, I've used to demonstrate the issue. Best regards, Michael
Any ideas what might be the root cause for this? I don't mind trying to solve it as it's currently keeping me from upgrading to v1.0.0