hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
185 stars 73 forks source link

Match rules leak when using addSigHandler/removeSigHandler #76

Closed littlefreaky closed 4 years ago

littlefreaky commented 5 years ago

In the DBusConnection class, the method addSigHandler (line 875) adds a match rule to the DBus interface by calling AddMatch unconditionally and puts the handler to the internal map used to keep track of the signal handlers. The method removeSigHandler (line 779) removes the signal handler from the internal map, but only calls RemoveMatch on the DBus interface if no other handler is in the map which matches the same SignalTuple.

This asymmetry causes a match rule leak when adding and removing multiple signal handlers which result in the same SignalTuple value. In my case, the application adds and removes handlers depending on state information. After some time, adding new match rules will fail because the maximum number of allowed rules is reached.

hypfvieh commented 5 years ago

I changed the addSigHandler (and addGenericSigHandler) method to only add the rule to DBus (calling AddMatch) if no other signal handler was added with that rule before.

Please test and report back.

littlefreaky commented 5 years ago

Thank you very much. I've tested the changes in my environment and can no longer reproduce the exceptions.

weliem commented 4 years ago

Great! I was facing the same issue.

Will there be a new release any time soon?

hypfvieh commented 4 years ago

I don't think that I'll create a new release in the near future as version 3.2.0 has been released recently and this is the first and only bugfix since release. I always wait to collect some bug fixes and improvements before creating a release.

My plan is to wait at least until the end of the year or maybe until mid/end of January 2020. We will see how many issues will be found and fixed until then.

weliem commented 4 years ago

Ok, understandable...no problem