FFI: global memory-limit tests are process-wide and can race the rest of the --lib suite
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia da bindings/ffi/src/limits.rs::ffi_roundtrips_global_limit e confronta la sua gestione del limite a livello di processo con tests/memory_limits.rs:18-59. Esamina bindings/ffi/Cargo.toml e src/utils/limits/memory.rs per comprendere i vincoli del processo di test. Il lavoro è completato quando i test dei limiti FFI sono sicuri durante l’esecuzione parallela di --lib, ripristinano i limiti dopo un errore e coprono il comportamento di enforcement previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
bindings/ffi/src/limits.rs::ffi_roundtrips_global_limit sets a process-global memory limit (456 bytes) with no serialization, while the other ~42 tests in the same regorus-ffi lib test binary run in parallel threads. Any concurrent test whose allocation check trips during that window can fail with a spurious LimitError::MemoryLimitExceeded.
This hasn't been observed failing — the window is short — but it's a latent flake, and more importantly it means there is currently no safe way to write a memory-limit test in the FFI crate at all.
Found while adding budget enforcement to the host-await accumulation paths in #672. That PR ships the enforcement without a test specifically because of this gap.
Why it's racy
GLOBAL_MEMORY_LIMIT is a process-wide AtomicU64 (src/utils/limits/memory.rs:9). cargo test --lib runs every unit test in one process across parallel threads, so a limit set by one test applies to all of them.
bindings/ffi/src/limits.rs:259-275:
#[test]
fn ffi_roundtrips_global_limit() {
let limit = 456_u64;
let result = regorus_set_global_memory_limit(limit, true);
// ... limit stays at 456 bytes across these assertions ...
let result = regorus_set_global_memory_limit(0, false);
regorus_result_drop(result);
}
No mutex, no #[ignore]. Concurrent tests that reach check_memory_limit_if_needed() during this window see a 456-byte ceiling. It's survivable today only because the window is ~4 atomic operations with no allocation-heavy work in between, and because the check amortizes (MEMORY_CHECK_STRIDE = 16, MEMORY_CHECK_DELTA_BYTES = 32 KiB, memory.rs:12-15), so most calls don't perform a real comparison.
If the test panics between set and clear, the limit is also never restored — every subsequent test in that process inherits it.
Contrast: the core crate does this correctly
tests/memory_limits.rs has 7 limit tests, all 7 take LimitGuard::lock(), 0 are ignored. It works because:
- It is an integration test, so it gets its own process — nothing else shares the global.
- Every test in the file takes the same mutex, and
Dropresets the limit toNone(tests/memory_limits.rs:18-59).
Why the FFI crate can't copy that pattern
bindings/ffi/Cargo.toml:11:
crate-type = ["cdylib", "staticlib"]
There is no rlib, so Rust integration tests under bindings/ffi/tests/ cannot link against the crate. All FFI tests must live in-crate as unit tests, sharing one process. The isolation that makes the core-crate pattern safe isn't available.
Impact
- Latent flakiness in
regorus-ffi--libruns, most likely to appear under high parallelism or on slower CI runners. - Blocks test coverage. Any FFI test that wants to assert limit-enforcement behaviour has to either accept the race or be
#[ignore]d out of CI. Concretely, #672 addscheck_memory_limit_if_needed()to the host-await accumulation loops and ships it untested for this reason — verified manually instead (1-byte limit →MemoryLimitExceeded, and mutation-checked that a test would catch its removal).
Possible directions
- Subprocess harness — a unit test re-execs the test binary with a marker env var and applies the limit only in the child. Keeps CI coverage, no crate-type change, ~30 lines of scaffolding.
- Add
rlibtocrate-type— enables a properbindings/ffi/tests/memory_limits.rswith the core crate'sLimitGuardpattern. Cleanest, but changes build output for all 9 bindings, so it needs a look at packaging/size implications. - Shared
LimitGuardinside the FFI crate — serializes limit-touching tests against each other, but not against the other ~42 that never take the lock. Partial mitigation only. - Minimum, regardless of the above — make
ffi_roundtrips_global_limitrestore the previous limit via aDropguard so a panic can't leak the 456-byte ceiling into the rest of the run.
Happy to send a PR for whichever direction is preferred.
References
bindings/ffi/src/limits.rs:259-275— unguarded global-limit testbindings/ffi/Cargo.toml:11—crate-typewithoutrlibsrc/utils/limits/memory.rs:9—GLOBAL_MEMORY_LIMITstaticsrc/utils/limits/memory.rs:12-15— amortization constantssrc/utils/limits/memory.rs:168-191—check_memory_limit_if_neededtests/memory_limits.rs:18-59— theLimitGuardpattern that works
- Lingua principale
- Rust
- Stelle
- 375
- Fork
- 81
- Merge medio
- 1g 11h
- PR unite (30g)
- 78
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Nessuna 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 microsoft/regorus
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
I maintainer di solito rispondono entro 1 giorno
-
RVM: errors and conflicts in rule bodies evaluate to undefined, even with strict builtin errorsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
microsoft/regorus#932 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 32/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/regorus
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
awxkee/yuvutils-rs#149 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Ignore entry for RUSTSEC-2026-0002 no longer matches anything (`lru` is no longer in `Cargo.lock`)Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
influxdata/influxdb#27767 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
shell-pool/shpool#463 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
oras-project/rust-oci-client-node#132 ·
I maintainer di solito rispondono entro 2 giorni