Skip to content

Runtime: don't drop a read request that arrives during export - #43

Open
Thoxy67 wants to merge 1 commit into
suchmememanyskill:mainfrom
Thoxy67:fix/lost-read-request
Open

Thoxy67 wants to merge 1 commit into
suchmememanyskill:mainfrom
Thoxy67:fix/lost-read-request

Conversation

@Thoxy67

@Thoxy67 Thoxy67 commented Nov 25, 2026

Copy link
Copy Markdown

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 sets read_retries_left[slot] = read_retries.

After a successful read, a parse error or "not present", the main loop did this for the same slot:

self._notify_exporters(scan_result, filament, reader, ExporterEvent.TAG_READ)
self.read_retries_left[i] = 0

_notify_exporters() is synchronous; with the webhook exporter it waits for an HTTP round trip. If a new start_reading_tag() for that slot arrives during that call, its counter is overwritten with 0 right 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.py adds a regression test. An exporter calls start_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 on main. 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 <= 0 check and the reset. I kept the change minimal since the reorder fixes the case that actually shows up.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant