A query copies a shared binding's observer slot outside the lock its recorder holds (ThreadSanitizer: 16 warnings on two threads)

オープン
#2,449 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c

調査の方向性

Start with vm_slot_query_view in src/vm.c and the observer record path in src/eigenscript.c, then inspect tests/test_tsan.sh and the instruction-count gate. Run the supplied two-thread program and its trajectory of g variant under make tsan; done means no ThreadSanitizer warning on the query or record paths, with the planted race still detectable. Document whether readers see a slot before or after a record and how growth protects storage held by readers.

索引モデルが issue の本文から書いたものです。

説明

area:concurrency area:observer found-by:critic kind:bug

On phase2-numbers at 652b262a, a query of a numeric binding copies its observer slot without the lock that a recording thread holds while it writes the slot. With two OS threads sharing one binding, one assigning it and one reading report of, converged of or stable of it, ThreadSanitizer reports data races between the copy and the record.

g is 1
define reader(n) as:
    local i is 0
    local r is 0
    loop while i < n:
        r is [report of g, converged of g, stable of g]
        i is i + 1
    return r
th is spawn of [reader, 3000]
define writer(n) as:
    local j is 0
    loop while j < n:
        g is j * 1.5
        j is j + 1
    return j
print of (writer of 3000)
print of (thread_join of th)

make tsan, run with setarch -R and TSAN_OPTIONS="halt_on_error=0 exitcode=0": 16 warnings on this program (30 with trajectory of g among the reads). The first:

WARNING: ThreadSanitizer: data race
  Write of size 1 by main thread (mutexes: write M0):
    #0 observer_slot_update_numeric_locked src/eigenscript.c:1229
    #1 observer_slot_update_numeric_shared src/eigenscript.c:1269
    #2 observer_slot_update_numeric src/eigenscript.c:1319
    #3 observer_slot_update src/eigenscript.c:1327
    #4 vm_run_ex src/vm.c:5869
  Previous read by thread T1:
    #0 vm_slot_query_view src/vm.c:459

The read is ObserverSlot q = *s in vm_slot_query_view: the whole slot copied outside the fold lock, then read. The write is the record under that lock. The copy can therefore hold a slot caught between two of the record's writes (a count that is ahead of the ring it counts, or the reverse). That is what the report shows. Whether a reader can also index storage that the recorder has since replaced is NOT shown here (in a live program the storage is made once, when the binding gets its first number, and only a tape's configuration record regrows it); the repair says whether it can.

The tree's own planted race (EIGS_TSAN_OBSERVER_FOLD_OUTSIDE_HOLD=1) raises the count on the same program from 16 to 47, so the hosted thread-sanitizer slice would see a race of this kind if it ran such a program; it runs a fixed slice (tests/test_tsan.sh) that has no reader of a shared numeric binding beside a writer.

Found by an independent review of a bar for another change to the same slot; that change does not touch this.

Done when

  • The program above (and its trajectory of g form) runs under make tsan with no warning whose stack holds vm_slot_query_view or the record path, on a head where the planted race still raises warnings (shown first).
  • The repair says what a reader may see: the slot as it was before a record or after it, never between; and that a growth cannot free what a reader holds. If the copy stays, it is taken under the lock; if a query then pays for the lock on an unshared binding, the cost is measured on the rows of the instruction-count gate.
  • tests/test_tsan.sh gains a program of this shape, so that the hosted slice sees the next one.

— Claude DevBox

主要言語
C
スター
3
フォーク
7
平均マージ
3時間 28分
マージ済み PR(30日)
270

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

InauguralSystems/EigenScript のほかの issue

InauguralSystems/EigenScript の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。