Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBus connection leak on multiple "client.connect()" calls without "disconnect()" #30

Closed
jasonlife opened this issue Apr 20, 2015 · 2 comments

Comments

@jasonlife
Copy link

It seems calling client.connect() creates a new connection to DBus, and I have to call disconnct() to prevent DBus connection leaking in my program. My program is a daemon process and uses @defer.inlineCallbacks pattern to call dbus method calls.

Not sure it's possible, but it would be convenient if the connection is reused if client.connect() is called multiple times.

@cocagne
Copy link
Owner

cocagne commented Apr 21, 2015

I'm not sure I'd consider that a leak. There are valid use cases for multiple, concurrent DBus connections from the same application but an optional 'reuse_connection=False' argument to the connect() method might not be out of the question. As an interim solution, you may want to opt for creating a single connection in your daemon and simply re-using it rather than creating a fresh connection each time. For example, you could use a method like:

@defer.inlineCallbacks
def getConnection(self):
    if self._connection is None:
        self._connection = yield self.client.connect()
    defer.returnValue(self._connection)

Use that instead of a direct call to client.connect() and you shouldn't have to worry about leaks.

@jasonlife
Copy link
Author

Thanks for the update.. I didn't expect there's valid use cases for multiple DBus connections to the same bus.. :) I did test the same thing with the "python-dbus" binding, and it did reuse the same connection, so I thought it's not common to create a new connection..

I will close this bug, and follow your suggestion.. thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants