endpoints: a far-future event panics inside write_lock and poisons it, so every later write returns 500 until restart

Aperta
#873 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@TimeToBuildBob ci sta già lavorando.

Dal 25/11/2026.

  • #904 di @TimeToBuildBob — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
api, backend

Direzione di ricerca

Start in aw-server/src/endpoints/bucket.rs, where bucket_events_create and bucket_events_heartbeat call event_range() while holding write_lock. The overflow comes from Event::calculate_endtime() in aw-models/src/event.rs (line 43), which uses plain +. Reproduce with the Rocket local client using a far-future timestamp, then confirm the endpoint returns 400 and that later writes still succeed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

In aw-server/src/endpoints/bucket.rs, both bucket_events_create and bucket_events_heartbeat call event_range() while holding state.write_lock (write_lock.lock().unwrap(), lines ~179 and ~224). event_range() calls Event::calculate_endtime() (aw-models/src/event.rs:43), which adds the duration with a plain +. That addition panics when the result overflows chrono's range.

An event with a far-future timestamp and a valid duration (< 292 years) therefore panics inside the lock and poisons the Mutex. Every later lock().unwrap() then panics too, so all event writes return 500 until the server restarts: every watcher's heartbeats, event creates, single and bulk deletes. The datastore's own range check (event_nanos) would return a clean 400, but it runs after this point.

Repro (Rocket local client, upstream master ea6f09c):

POST /api/0/buckets/aw-watcher-web-firefox/heartbeat?pulsetime=1
{"timestamp":"+262000-01-01T00:00:00Z","duration":9e9,"data":{}}
-> 500 (panic: `DateTime + TimeDelta` overflowed)

POST /api/0/buckets/aw-watcher-web-firefox/heartbeat?pulsetime=1
{"timestamp":"2026-01-01T00:00:00Z","duration":0,"data":{}}
-> 500   (and the same for POST .../events and DELETE .../events/1)

POST .../events with the same far-future event gives the same result. A browser extension can send it too: the default CORS rule admits moz-extension:// origins for aw-watcher-web-* buckets. So one buggy client clock or extension takes data collection down for every watcher, silently, until restart.

Suggested fix

  1. Compute the range with checked_add_signed and return 400 before taking the lock. Or validate the event's range first and take the lock after.
  2. Stop the lock from failing permanently, e.g. lock().unwrap_or_else(PoisonError::into_inner). It guards only ordering and protects no invariant that a panic could break.

Found in a verified review pass over the endpoints. No PR from me yet, because I already have three open from this pass (#869, #870, #871).

Lingua principale
Rust
Stelle
322
Fork
107
Merge medio
2g 16h
PR unite (30g)
25

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ActivityWatch/aw-server-rust

Tutte le issue di ActivityWatch/aw-server-rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.