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
- 平均合併
- 6 小時 23 分鐘
- 30 天內合併 PR
- 2
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ruby/weakref 的其他 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
-
ds-drift
難度 1/5 1 小時以內 新手友好度 76/100
we-promise/sure#4120 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 4 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
scanaislop/aislop#476 ·
維護者通常 1 天內回覆