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

Abierto
#873 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@TimeToBuildBob ya está trabajando en esto.

Desde el 25/11/2026.

  • #904 de @TimeToBuildBob — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
api, backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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).

Lenguaje dominante
Rust
Estrellas
322
Forks
107
Merge medio
2 d 16 h
PR fusionados (30 d)
25

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ActivityWatch/aw-server-rust

Todos los issues de ActivityWatch/aw-server-rust

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.