moquette-io / moquette

Java MQTT lightweight broker
http://moquette-io.github.io/moquette/
Apache License 2.0
2.27k stars 814 forks source link

Subscriptions not removed on dropped connections #752

Open hylkevds opened 1 year ago

hylkevds commented 1 year ago

When a session is cleaned up, active subscriptions are not removed from the CTrieSubscriptionDirectory repository. This is a memory leak and causes unnecessary processing when the broker tries to send messages to these phantom subscriptions.

When subscriptions are cleaned up for expired sessions the interceptor should also be notified of this.

hylkevds commented 1 year ago

In our internal version I made a hack to implement this: https://github.com/FraunhoferIOSB/moquette/commit/3756936b842ea75508fef6a2fc7f4df767334fa4 Definitely not the cleanest way, but may be of use for inspiration.

The tricky bit is getting the unsubscribe notification to the interceptor, since the PostOffice is not involved, since there is no unsubscribe message. In my hack I solved this by giving the SessionRegistry a reference to the interceptor.