Repository navigation
Count a probe that did not complete as a failure - #34
Open
drHouse-gif wants to merge 1 commit into
Open
drHouse-gif wants to merge 1 commit into
drHouse-gif wants to merge 1 commit into
Conversation
ProbeStatus.ERROR was produced but matched by nothing in _attempt_connect, so the endpoint's ConnectMeta was left untouched: no attempt counted and next_retry_at unmoved. The endpoint stayed due and was re-probed on every heartbeat instead of following the backoff. Two routes reach that status. The explicit one is connect() reporting a live link while _shelly_device.connected is already False by the check immediately after it. The implicit one is DeviceProbeResult defaulting to ERROR, so any exception raised before a status is assigned lands there as well. Both mean the probe did not complete, so both are counted as a failure, and reported separately from UNREACHABLE because that is a device that never answered at all. The explicit route is driven end to end. Shelly.GetComponents is the last RPC of connect(): what follows it, _get_channels_info_from_components, works off the config already embedded in that response and makes no further call. A websocket closed right after it is answered therefore leaves connect() with everything it needs, so it returns True, while the check on the next line sees a disconnected device. mock/mock_shelly_server.py gains --ws-close-after-method for that. Anchoring on the method name rather than on a count of served frames is deliberate: a count is timing dependent and silently stops hitting the window, which it did on a second machine. tests/test_probe_status_error.py asserts the branch is entered and that the delays it then reports are 10, 20, 40 rather than the heartbeat interval. Both of its tests fail with this change reverted. tests/test_probe_status_coverage.py guards the wider class of bug, a status produced with no consumer, by reading the dispatch; its second test fails with this change reverted too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
One commit on
master(d8cb65d, v2.21).discovery.py+12,mock/mock_shelly_server.py+11, two new test files: 141 insertions, no deletions.The problem
_attempt_connectdispatches on the probe result, andProbeStatus.ERRORis matched by nobranch at all. An endpoint whose probe returns it gets no
mark_success, nomark_failureandno
stop_connect, so itsConnectMetais left exactly as it was:attemptsnot incremented,next_retry_atnot moved. The endpoint therefore stays due and is re-probed on the nextheartbeat, and the one after that, without the attempt ever being counted.
Two routes lead to that status:
discovery.py:919connect()returned True, but_shelly_device.connectedis already False at the check immediately after itdiscovery.py:73DeviceProbeResult.statusdefaults toProbeStatus.ERROR, so any exception raised in_get_device_infobefore a status is assigned returns itThe implicit route is narrow in practice, because
ShellyDevice.connect()wraps its body inexcept Exception: return False. It does still leak out of the handler's own cleanup:self._shelly_device.shutdown()andself._aiohttp_session.close()are awaited inside thatexceptand are not themselves guarded. Reachable, not reproduced, and I have labelled it assuch rather than claiming otherwise.
The change
One branch, matching on the status rather than on how it arose, so both routes are covered:
UNREACHABLEkeeps its own branch and its own message. The wording deliberately avoids saying"connected and then dropped", even though that is the route I reproduced, because the implicit
route can arrive here without the device having answered.
The separate message is also the only way an operator can currently tell this case from a
device that never answered at all.
How the scenario is driven
Shelly.GetComponentsis the last RPC ofShellyDevice.connect(). What follows it,_get_channels_info_from_components, works off theconfigalready embedded in that responseand makes no further call. So a websocket closed right after that answer leaves
connect()with everything it needs - it returns True - while the check on the very next line sees a
disconnected device.
The mock gains
--ws-close-after-methodfor exactly that. Anchoring on the method name ratherthan on a count of served frames is deliberate, and learned the hard way: a frame count
reproduced the window on one machine and silently stopped hitting it on another, where the
probe simply completed and the test passed without exercising anything.
Tests
tests/test_probe_status_error.pytests/test_probe_status_coverage.pyThe first asserts the branch is entered and reported. The second asserts the delays it reports
are 10, 20, 40 - the doubling backoff - rather than the heartbeat interval.
test_probe_status_coverage.pyreads the dispatch rather than the behaviour, on purpose: itguards the wider class of bug, a
ProbeStatusproduced with no consumer, and keeps working ifthe dispatch is restructured.
Full suite: 79 passed, 4 xfailed, 1 failed on aioshelly 12.0.0, against a pristine v2.21
baseline of 75 passed, 4 xfailed, 1 failed. The one failure,
test_timeouts.py::test_freeze_longer_than_reconnect_loop, is pre-existing: it fails onunmodified v2.21 with aioshelly 12.0.0, which is the version the Venus OS recipe pins and a GX
actually runs, and it passes on 14.1.0, which CI installs unpinned.
Interaction with the other proposed change
fix/unsupported-device-not-listedtouches a neighbouring branch of the sameif/elifchain.discovery.pymerges cleanly between the two. They do overlap by one line inmock/mock_shelly_server.py, where both add a constructor argument at the end of the sameparameter list; the resolution is to keep both lines. Neither change depends on the other.