-
Notifications
You must be signed in to change notification settings - Fork 559
fix: fix keep-alive timeouts on small intervals #667
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
fix: fix keep-alive timeouts on small intervals #667
Conversation
2d8a8e6 to
dd9e000
Compare
The check interval calculation in the `ping.go` file has been adjusted for when the keep-alive time is less than or equal to 10. Instead of dividing by 2, the check interval now is calculated with a division by 4, ensuring a more frequent ping check. This is required as MQTT brokers typically detect a timeout if the client did not send a ping within the specified keep-alive interval times 1.5. If the client only checks for due pings every half-interval, this commonly leads to timeouts. An example: a 5 second interval means that every 2.5 seconds checks are made for due pings. However, if checks have occurred at 2.49 seconds since the last ping and 4.99 seconds, the next one might happen slightly after 7.5 seconds, making the broker detect a timeout. Therefore, we increase the frequency of ping checks by reducing the check interval.
dd9e000 to
08d0637
Compare
|
Oh and in case this isn't already clear: This might be considered a critical bug as the library is nearly unusable with keep-alive timeouts below 10-11 seconds. So I'd be very happy if this is released as soon as possible (: Thanks guys! |
|
Thanks for the fix.
This is mandated in the spec "...within one and a half times the Keep Alive time period, it MUST disconnect...".
This is likely to be fairly common given that pings are sent/checked on the same
The algorithm (with minor changes) has been in place since 2017, so this has obviously not been too much of an issue (I suspect that very few users require such frequent pings). As such, I'm accepting the PR but don't intend to issue a release because of it (you can just use Note that the v5 client uses a different approach ,that I believe will result in more accurate checks. It might be worth considering moving to that model here (but the code there is pretty new so no where near as well tested as this). |
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/eclipse/paho.mqtt.golang](https://github.com/eclipse/paho.mqtt.golang) | require | minor | `v1.4.3` -> `v1.5.0` | --- ### Release Notes <details> <summary>eclipse/paho.mqtt.golang (github.com/eclipse/paho.mqtt.golang)</summary> ### [`v1.5.0`](https://github.com/eclipse/paho.mqtt.golang/releases/tag/v1.5.0) [Compare Source](eclipse-paho/paho.mqtt.golang@v1.4.3...v1.5.0) In the year since the release of v1.4.3 the majority of changes have been small incremental improvements/fixes. One notable change is that Go v1.20+ is now required (due to MR [#​646](eclipse-paho/paho.mqtt.golang#646)). #### What's Changed - Wrap connection network errors by [@​adriansmares](https://github.com/adriansmares) in eclipse-paho/paho.mqtt.golang#646 - Clarify use of token.WaitTimeout by [@​MattBrittan](https://github.com/MattBrittan) in eclipse-paho/paho.mqtt.golang#659 - fix ([#​661](eclipse-paho/paho.mqtt.golang#661)): Add NewClientOptionsReader for mocking purposes. by [@​avmunm](https://github.com/avmunm) in eclipse-paho/paho.mqtt.golang#662 - fix: fix keep-alive timeouts on small intervals by [@​lefinal](https://github.com/lefinal) in eclipse-paho/paho.mqtt.golang#667 - Replace the time.After with the timer for efficiency. by [@​DVasselli](https://github.com/DVasselli) in eclipse-paho/paho.mqtt.golang#671 - fix: deprecation warnings for ioutil by [@​vruge](https://github.com/vruge) in eclipse-paho/paho.mqtt.golang#665 - fix: issue 675:goroutine leak when connectionUp(true) return error by [@​kiqi007](https://github.com/kiqi007) in eclipse-paho/paho.mqtt.golang#678 - Update dependencies by [@​MattBrittan](https://github.com/MattBrittan) in eclipse-paho/paho.mqtt.golang#683 #### New Contributors - [@​adriansmares](https://github.com/adriansmares) made their first contribution in eclipse-paho/paho.mqtt.golang#646 - [@​avmunm](https://github.com/avmunm) made their first contribution in eclipse-paho/paho.mqtt.golang#662 - [@​lefinal](https://github.com/lefinal) made their first contribution in eclipse-paho/paho.mqtt.golang#667 - [@​DVasselli](https://github.com/DVasselli) made their first contribution in eclipse-paho/paho.mqtt.golang#671 - [@​vruge](https://github.com/vruge) made their first contribution in eclipse-paho/paho.mqtt.golang#665 - [@​kiqi007](https://github.com/kiqi007) made their first contribution in eclipse-paho/paho.mqtt.golang#678 **Full Changelog**: eclipse-paho/paho.mqtt.golang@v1.4.3...v1.5.0 </details> --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44MC4wIiwidXBkYXRlZEluVmVyIjoiMzguODAuMCIsInRhcmdldEJyYW5jaCI6Im1hc3RlciIsImxhYmVscyI6W119--> See merge request alpine/infra/build-server-status!15
The check interval calculation in the
ping.gofile has been adjusted for when the keep-alive time is less than or equal to 10. Instead of dividing by 2, the check interval now is calculated with a division by 4, ensuring a more frequent ping check. This is required as MQTT brokers typically detect a timeout if the client did not send a ping within the specified keep-alive interval times 1.5. If the client only checks for due pings every half-interval, this commonly leads to timeouts. An example: a 5 second interval means that every 2.5 seconds checks are made for due pings. However, if checks have occurred at 2.49 seconds since the last ping and 4.99 seconds, the next one might happen slightly after 7.5 seconds, making the broker detect a timeout. Therefore, we increase the frequency of ping checks by reducing the check interval.