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

未关闭
#271 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
haskell
领域
testing

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
Haskell
星标
57
派生
25
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

IntersectMBO/io-sim 的其他 Issue

查看 IntersectMBO/io-sim 的全部 Issue

相似的 Issue

更多 Haskell Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。