Docstring of `Bounded.State` (Std.Sync.Channel) lists three invariants that fail between critical sections
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 86/100
- Tipo di issue
- Documentazione
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- documentation
Direzione di ricerca
Leggi il docstring di Bounded.State in src/Std/Sync/Channel.lean, in particolare gli invarianti intorno alle righe 370–377, insieme al comportamento di risveglio in trySend' e tryRecv' intorno alle righe 474 e 531. Aggiorna la formulazione per tenere conto del fatto che i processi in attesa risvegliati riprovano in sezioni critiche successive, usando come guida la riformulazione proposta nell’issue. Il lavoro è completato quando il docstring descrive quando valgono questi invarianti e i casi indicati in cui possono essere temporaneamente violati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”) - When reporting a perceived soundness bug: Does it affect
lake check --paranoid?
If in doubt, please reach out on [email protected] for responsible disclosure.
Description
The docstring of the bounded channel's state (Channel.lean#L370-L377) lists these invariants:
2. `0 < bufCount → consumers = ∅`
3. `bufCount < capacity → producers = ∅`
4. `producers = ∅ ∨ consumers = ∅`, implied by 1, 2 and 3.
All three can be false between two critical sections. trySend' wakes only the first queued consumer (L474) and tryRecv' only the first queued producer (L531), and the woken waiter retries in a later critical section, so other sends and receives can run first. The three hold again once every woken waiter has retried.
Context
I found this while checking a model of the bounded channel with Veil, where all three came out false as invariants.
Steps to Reproduce
On a channel of capacity 1:
- Two
recvs on the empty channel: both queue inconsumers. send 1buffers 1 and wakes the first receiver only, sobufCount = 1while the second is still queued (2 fails).- Before the woken receiver retries,
send 2finds the buffer full and queues, soproducersandconsumersare both nonempty (4 fails).
For 3: send 1 is buffered, send 2 and send 3 queue, then one recv takes 1 and wakes only send 2, so bufCount = 0 while send 3 is still queued.
Expected behavior: the listed invariants hold whenever the lock is free.
Actual behavior: 2, 3 and 4 can fail between critical sections while woken waiters have yet to retry.
Versions
Lean (version 4.38.0-nightly-2026-11-29, x86_64-unknown-linux-gnu, commit 80362eeeada90bd5e5b0aae9d1d15dd95978a6d4, Release). The text is the same on master and in v4.36.0. Amazon Linux 2023.
Additional Information
A possible rewording:
1. `0 < capacity`
-2. `0 < bufCount → consumers = ∅`
-3. `bufCount < capacity → producers = ∅`
-4. `producers = ∅ ∨ consumers = ∅`, implied by 1, 2 and 3.
+2. `0 < bufCount → consumers = ∅`, once every woken consumer has retried
+3. `bufCount < capacity → producers = ∅`, once every woken producer has retried
+4. `producers = ∅ ∨ consumers = ∅`, once every woken waiter has retried (by 1, 2 and 3)
5. `bufCount` corresponds to the amount of slots in `buf` that are `some`.
6. `sendIdx = (recvIdx + bufCount) % capacity`. However all four of these values still get tracked
as there is potential to make a non-blocking send lock-free in the future with this approach.
7. `closed = true → consumers = ∅ ∧ producers = ∅`
+
+A send wakes only the first queued consumer and a receive only the first queued producer, and the
+woken waiter retries in a later critical section. Until it has, a value can be buffered while
+consumers are queued, a slot can be free while producers are queued, and both queues can be
+nonempty.
Happy to send it as a PR if that's easier :)
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
- Lingua principale
- Lean
- Stelle
- 10.5k
- Fork
- 1.2k
- Merge medio
- 17h 55m
- PR unite (30g)
- 356
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di leanprover/lean4
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
leanprover/lean4#16892 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
leanprover/lean4#16842 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
leanprover/lean4#16841 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
leanprover/lean4#16840 ·
I maintainer di solito rispondono entro 1 giorno
-
doc: stray "public" in Bool and HEq documentationForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
leanprover/lean4#16825 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di leanprover/lean4
Issue simili
-
bug improve content
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
opensafely/documentation#2102 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
agentregistry-dev/website#69 ·
-
15.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
-
docs: add SECURITY.md vulnerability reporting policyForse già presa @AK-Lmn l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
flisk-sh/linux2wasm#12 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno