WeakRef requires rescuing RefError to avoid race condition
还没有人认领这个 Issue。
评估
调研方向
从 WeakRef API 开始,重点关注 weakref_alive?、委托访问、RefError 处理以及不推荐的 WeakMap 替代方案。阅读链接的 Stack Overflow 讨论,了解竞态条件的背景;完成的标准是就一个 API 达成一致并完成实现:对象存活时安全地返回一个具有强引用的对象,否则返回 nil。
由索引模型根据 Issue 内容生成。
描述
There's an race condition in the implied usage of WeakRef.
The API only has weakref_alive?, and then delegated access to the referenced object. But the delegated access to the object cannot be protected by weakref_alive? since GC may occur between the check and the usage.
This means we basically always have to check for RefError, which basically makes weakref_alive? useless if we want to actually potentially use the object.
WeakMap usage is discouraged, leaving us with needing to add this functionality to WeakRef, which may break if WeakRef implementation changes (i.e., there is no good solution for this).
This is discussed at length here:
https://stackoverflow.com/questions/69185508/ruby-weakref-has-implicit-race-condition
I would recommend an addition to the API that will safely return a (non-weak) object if it's alive, or else nil, and obviously it's up to the user to realize that this will stop GC from happening on that object while they hold it.
- 主要语言
- Ruby
- 星标
- 20
- 派生
- 8
- 平均合并
- 9 小时 32 分钟
- 30 天内合并 PR
- 1
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/weakref 的其他 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
palladius/rails8-app-on-gcp#145 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
rubocop/rubocop-rspec#2236 ·
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
riscv/riscv-unified-db#2624 · 1 个 reaction ·
-
难度 1/5 1 小时以内 新手友好度 88/100