IOSim: timeout can return while its assasin threas is still ailve

Abierto
#271 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
haskell
Área
testing

Línea de trabajo

Start by reading the IOSim implementation of timeout, its assassin thread, and the runSimStrictShutdown checks; the issue gives six reproductions using threadDelay, yield, and STM. Trace the tie cases where the assassin remains queued or has a pending ThreadKilled, then verify that all scenarios finish without FailureSloppyShutdown while preserving their stated results.

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

Descripción

bug

Describe the bug
timeout can return while its assassin thread is still alive, so runSimStrictShutdown fails with FailureSloppyShutdown

In IOSim, timeout forks an assassin thread when its timer fires. If the action finishes at the same moment the timeout expires, timeout can return while the assassin is still alive. Any simulation run with runSimStrictShutdown then fails with FailureSloppyShutdown.

The result itself is correct: the leftover assassin never throws. But in simulations the action often finishes exactly at the deadline, so this makes strict shutdown unusable for code that uses timeout. GHC has no equivalent of the strict-shutdown check, so the problem only shows up in the simulator.

To Reproduce

Each scenario run with runSimStrictShutdown:

Scenario Code Result
a. timer never fires timeout 1 (threadDelay 0.5) Just ()
b. timeout wins timeout 1 (threadDelay 2) Nothing
c. tie, action finishes first timeout 1 (threadDelay 1) FailureSloppyShutdown
c′. c, then yield timeout 1 (threadDelay 1) <* yield FailureSloppyShutdown
d. tie, action yields before finishing timeout 1 (threadDelay 1 >> atomically (pure ())) FailureSloppyShutdown
d′. d, then yield timeout 1 (threadDelay 1 >> atomically (pure ())) <* yield Just ()
  • Case c: the assassin hasn't run yet. At 1s the delay timer wakes the main thread, and the timeout timer forks the assassin, which is queued behind main.
    Main leaves the TimeoutFrame, takes the lock and finishes. The assassin is still in the run queue, so TraceMainReturn lists it as running. A yield
    doesn't help: the assassin's tryPutTMVar commit yields too, so main finishes before the assassin exits.
  • Case d: the assassin holds the lock but hasn't thrown yet. The frame exit killThreads it. Killing an unmasked thread doesn't block; it only replaces the
    thread's next action with Throw ThreadKilled. So the assassin isn't dead yet when main finishes. One yield lets it terminate, which is why d′ passes.
Lenguaje dominante
Haskell
Estrellas
57
Forks
25
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

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 IntersectMBO/io-sim

Todos los issues de IntersectMBO/io-sim

Issues similares

Más issues de Haskell

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.