-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
Bug: Watcher sends duplicate query at startup
Summary
The new_watcher function executes its query function twice at startup due to Tokio's time::interval first tick completing immediately. The second query is redundant, and its result overwrites the first - so a transient failure on the second query can replace valid data with empty/incorrect results.
Observed Behavior
Debug logging confirms two identical queries at startup:
23:23:40.272Z DEBUG: get_allocations called, closed_at_threshold_secs: 1766877820
23:23:41.233Z allocations: N
23:23:41.234Z DEBUG: get_allocations called, closed_at_threshold_secs: 1766877821
23:23:48.767Z allocations: N
Both queries use the same parameters (1 second threshold difference is negligible on a 30-day buffer). However, in earlier testing the second query intermittently returned 0 allocations instead of the correct value, overwriting the valid first result and causing receipt validation failures. There is a PR to fix this here #912
Root Cause
// crates/watcher/src/lib.rs
let initial_value = function().await?; // Query 1
let (tx, rx) = watch::channel(initial_value);
tokio::spawn(async move {
let mut time_interval = time::interval(interval);
loop {
time_interval.tick().await; // Returns IMMEDIATELY on first tick
let result = function().await; // Query 2 (redundant)
tx.send(result)... // Overwrites initial_value
}
});Metadata
Metadata
Assignees
Labels
No labels