Repository navigation
Conversation
loop() reset read_retries_left[i] to 0 after notifying the exporters. Exporters are synchronous and can be slow (webhook), and start_reading_tag() runs on the controller thread, so a request for the same slot made during the export was overwritten and never processed. Reset the counter before notifying, in all three branches, and add a regression test.
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.
I ran into a race in
Runtime.loop()where a read request is silently dropped.The problem
start_reading_tag(slot)is called from the controller thread (Moonraker remote method / property change) and simply setsread_retries_left[slot] = read_retries.After a successful read, a parse error or "not present", the main loop did this for the same slot:
_notify_exporters()is synchronous; with the webhook exporter it waits for an HTTP round trip. If a newstart_reading_tag()for that slot arrives during that call, its counter is overwritten with0right after and the request never runs. Only the "Received request to read tag" line shows up in the log. In practice this happens when two reads are triggered on the same slot in quick succession, e.g. swapping spools quickly, with a webhook that takes a moment to answer.The fix
The counter is now reset before the exporters are notified, in all three branches (
TAG_READ,TAG_PARSE_ERROR,TAG_NOT_PRESENT), so a request that arrives during the export survives until the next pass. Behaviour is otherwise unchanged.Test
test/test_runtime.pyadds a regression test. An exporter callsstart_reading_tag(0)while it is being notified, and the test checks that the request is still pending after the loop pass, for each of the three outcomes. It passes with the fix and fails onmain. The full suite passes (98 passed, 1 skipped).A per-slot request counter or a lock would also close the tiny remaining window between the
<= 0check and the reset. I kept the change minimal since the reorder fixes the case that actually shows up.