WeakRef requires rescuing RefError to avoid race condition
まだ誰も着手していません。
評価
調査の方向性
WeakRef API から始め、特に weakref_alive?、委譲アクセス、RefError の処理、推奨されない代替手段である WeakMap を確認してください。Race condition の文脈については、リンクされた Stack Overflow の議論を読んでください。完了とは、生存している場合は強い参照を持つオブジェクトを安全に返し、それ以外の場合は nil を返す API に合意し、実装することです。
索引モデルが 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分
- マージ済み PR(30日)
- 1
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/weakref のほかの issue
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
palladius/rails8-app-on-gcp#145 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
rubocop/rubocop-rspec#2236 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
riscv/riscv-unified-db#2624 · リアクション 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100