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

Aberta
#2,449 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
48/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
c

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
C
Estrelas
3
Forks
7
Merge médio
3h 28min
PRs com merge (30d)
270

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de InauguralSystems/EigenScript

Todas as issues de InauguralSystems/EigenScript

Issues semelhantes

Mais issues de C

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.