Hi,
We are currently using an expiry interval for retained messages with different topics to make sure that unrequired messages get automatically deleted by the broker. We recently noticed that the metrics exposed by the topics "$SYS/broker/store/messages/count" and "$SYS/broker/retained messages/count" increased to unexpected high values although we set message expiry intervals. From tests / observations we conducted we conclude that expired retained messages are currently only removed if new subscriptions on their topics are created by clients.
In our usage scenario this behavior currently causes a constantly increasing retained message count and of course memory amount. Thus, as a workaround we consider to call mosquitto_sub -t '#' regularly to trigger the message clean up.
Is there a mosquitto setting, we missed, that triggers regularly an automatic clean up of expired retained messages?
Steps to reproduce our observations
- starting mosquitto broker version 2.0.20 with default settings;
- observation of metric "$SYS/broker/store/messages/count" with
mosquitto_sub -t '$SYS/broker/store/messages/count';
- initially metric reports 51 stored messages;
- publishing 10 retained messages with an expiry interval of 10 seconds with following bash script:
for i in $(seq 1 10);
do
mosquitto_pub -t "/test/$i" -r -m test -D publish message-expiry-interval 10 -V 5
done
- the metric increases to 61 (as expected); nevertheless, stays at this value even after 10 seconds;
- calling
mosquitto_sub -t '/test/1' reduces the the message count to 60;
- calling
mosquitto_sub -t '#' decreases the count to 51 - the initial value;
Related code lines
The removal of expired retained messages seems to take place in the code at following lines:
|
if(branch->retained->message_expiry_time > 0 && db.now_real_s >= branch->retained->message_expiry_time){ |
|
db__msg_store_ref_dec(&branch->retained); |
|
branch->retained = NULL; |
|
#ifdef WITH_SYS_TREE |
|
db.retained_count--; |
|
#endif |
Hi,
We are currently using an expiry interval for retained messages with different topics to make sure that unrequired messages get automatically deleted by the broker. We recently noticed that the metrics exposed by the topics "$SYS/broker/store/messages/count" and "$SYS/broker/retained messages/count" increased to unexpected high values although we set message expiry intervals. From tests / observations we conducted we conclude that expired retained messages are currently only removed if new subscriptions on their topics are created by clients.
In our usage scenario this behavior currently causes a constantly increasing retained message count and of course memory amount. Thus, as a workaround we consider to call
mosquitto_sub -t '#'regularly to trigger the message clean up.Is there a mosquitto setting, we missed, that triggers regularly an automatic clean up of expired retained messages?
Steps to reproduce our observations
mosquitto_sub -t '$SYS/broker/store/messages/count';mosquitto_sub -t '/test/1'reduces the the message count to 60;mosquitto_sub -t '#'decreases the count to 51 - the initial value;Related code lines
The removal of expired retained messages seems to take place in the code at following lines:
mosquitto/src/retain.c
Lines 161 to 166 in 7f50849