Timer timing issue
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- ruby
调研方向
从 state_manager.rb 和 issue 中描述的 history_window 事件处理循环开始。复现 sleep 完成和计时器触发在同一个历史批次中到达的工作流场景,然后将当前行为与所引用的 Java 和 Rust SDK 行为进行比较。该 issue 目前还没有达成一致的实现方案或完成定义。
由索引模型根据 Issue 内容生成。
描述
temporal-ruby Timer timing issue
Scenario:
- Timer started (30 minutes)
- Sleep started by workflow code (15 minute)
- Worker goes down
- Sleep ends
- Timer fires.
- Worker comes back up
- Worker receives a history containing the sleep finishing followed by timer firing.
The workflow thus receives two TIMER_FIRED events in its history at once. Now what should happen?
What’s happening in temporal-ruby today
It processes the timers in order. Sleep first, then the other timer. The workflow completes first, and it’s not allowed to do anything after the workflow has completed. Thus, if the timer issues a command, the task will fail with Temporal::WorkflowAlreadyCompletingError.
Attempted solution
My first attempt was to early-out in state_manager.rb
history_window.events.each do |event|
apply_event(event)
break if if workflow_finished?
end
This fixed my problem and is logical; the workflow will execute the same as it would have if the worker had never gone down. But, it will silently drop events.
I asked Maxim what other SDKs do…
Other SDKs’ behaviors
According to Maxim:
Temporal processes new events in batches. One batch per workflow task. It applies all the events before running workflow code. So in case of Java or Go, for example the Futures that correspond to timer will be set to ready before running any workflow threads. This way workflow can check if any of these Futures are ready to decide what to do next.
Signals have similar properties, but they use callbacks in Java and some other SDKs. Temporal SDK schedules callback threads before running workflow threads. This way workflow cannot complete before the callback threads were called.
Then in case of Java SDK it is going to make the main workflow thread eligible to run. But it still will run only after all other threads executed and all other Futures resolved.
Without this functionality you guaranteed to lose signals if they are delivered as callbacks.
Rust core does the same
Java implementation - we can a see that callbacks (timer in this case) have a higher priority than the main thread (which is awoken by the sleep in this case).
What now?
Changing temporal-ruby's behavior is obviously somewhat tricky and would cause version changes if not done in a version-safe way. We might take this fix on but want to work with the community.
- Should we fix this?
- Implementation suggestions for the fix itself?
- Version safety. I'm guessing we should add a configuration that changes this behavior that folks can opt into.
- 主要语言
- Ruby
- 星标
- 288
- 派生
- 113
- 平均合并
- 14 天 20 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
coinbase/temporal-ruby 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
coinbase/temporal-ruby#361 ·
-
难度 3/5 1-2 天 新手友好度 35/100
coinbase/temporal-ruby#341 ·
-
难度 5/5 一周以上 新手友好度 25/100
coinbase/temporal-ruby#328 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 45/100
coinbase/temporal-ruby#326 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
coinbase/temporal-ruby#324 · 3 条评论 · 2 个 reaction ·
查看 coinbase/temporal-ruby 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 90/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
mastodon/mastodon#40755 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
L: docker L: elm L: github:actions L: helm L: ruby:bundler
难度 2/5 1-3 小时 新手友好度 85/100
dependabot/dependabot-core#16425 ·
维护者通常 2 天内回复