server: Default value of MaximumMessageExpiryInterval
We are having problems with retained messages being deleted exactly one day after publishing. I guess the source lies in the server.Options.Capabilities.MaximumMessageExpiryInterval property.
When starting the server with nil options (default capabilities):
server := mqtt.New(nil)
the server.Options.Capabilities.MaximumMessageExpiryInterval is set to 86400 seconds (exactly 1 day).
Shouldn’t it be the maximum possible int64 value to better represent the fact that the server was started without a maximum message expiry interval?
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 17 (12 by maintainers)
@dadebue Hope you feel better soon! Remember to get plenty of rest and water!
❤️ I’m sorry to hear that . Take your time to recover, and we can address the issue once you’re feeling better.
I was struggling with a cold for a few days…
I’ve reviewed and added a comment…
@dadebue Refer to Create a pull request
This needs some more thought! I tried setting the
MaximumMessageExpiryIntervalvalues to0ormath.MaxInt. And in both cases the retained messages are cleared right away.The problem lies in line 1600 of
server.go:The second condition is always true for
0andMath.MaxInt:0it’s true becauseCreatedis always smaller thannowmath.MaxIntit’s true because of Go integer overflow (variable wraps around and becomes negative and therefore is smaller thatnow)I suggest something like this (variable declaration just for readability):
@dadebue This is a very good point. I’ve added it to the README - let me know if it’s unclear or needs improvement 🙂 Thank you for raising it!
Hi @dadebue!
This is correct -
math.MaxIntallows an effectively infinite number of retained and inflight messages to queue up on the server. In a hostile network environment, this can be used to DOS the broker, and we didn’t feel comfortable releasing with this as the default configuration. For this reason we opted for a ‘safer’ default value.You can still configure it to use
math.MaxInt, or some other value, however.🙂Happy to discuss increasing this default value, too.