Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(at least on MacOS) the
call_later
-target is executed some milliseconds before the set timeout and therefore the ping will not be sent in a valid time for the broker.Explanation:
For example: if
keepalive
is set to 2 seconds timeout, the call will eventually be made after 1.91(+-) seconds. Thus, the first call comes in after 1.91 seconds and the comparisonif time.monotonic() - self._last_data_in >= self._keepalive
will evaluate to false. The second call will be made after 3.92 seconds - but its already too late to send the ping to the broker then, because the maximum tolerance on broker-side is 1.5 *keepalive
.As the timeout for
call_later
is already equal tokeepalive
, we can simply remove the double check inside the_keep_connection
to have everything worky.