# `Odb: Sync` lets `Mempack::reset` race with `Odb` writes on another thread
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 15/100
Línea de trabajo
The race sits between Mempack::reset and Mempack::dump in src/mempack.rs (lines 35-48), which call the backend without the odb lock, and the Send + Sync claim on Odb in src/odb.rs (lines 23-25). Read the reproducer in the issue and run it under ThreadSanitizer to confirm the race. Done means choosing and implementing a fix: either make reset and dump unsafe with a documented no-concurrent-use requirement, or add locking to libgit2's odb_mempack.c. That choice needs maintainer input first.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Odb is Send + Sync (src/odb.rs:23-25) because "git_odb uses locking and atomics
internally". That covers the git_odb_* functions, which hold the odb's lock while they call into a
backend. Mempack::reset and Mempack::dump (src/mempack.rs:35-48) call git_mempack_reset /
git_mempack_dump on the backend directly, without that lock, and the mempack backend has no lock
of its own. Mempack is !Send, but it only borrows the Odb, so another thread holding &Odb
can write into the backend while the owning thread resets it:
#![forbid(unsafe_code)]
fn main() {
let odb = git2::Odb::new().unwrap();
let mempack = odb.add_new_mempack_backend(1000).unwrap();
std::thread::scope(|s| {
s.spawn(|| {
for i in 0..2000 {
odb.write(git2::ObjectType::Blob, format!("blob {i}").as_bytes()).unwrap();
}
});
for _ in 0..2000 {
mempack.reset().unwrap();
}
});
}
git2-rs b9d59b6 (0.21.0) with libgit2 1.9.7, under ThreadSanitizer (5 runs of 5):
WARNING: ThreadSanitizer: data race
Write of size 8 by thread T1 (mutexes: write M0):
#0 git_odb_mempack_oidmap__resize libgit2/src/libgit2/odb_mempack.c:31:1
#3 impl__write libgit2/src/libgit2/odb_mempack.c:57:6
#4 git_odb_write libgit2/src/libgit2/odb.c:1645:12
Previous read of size 8 by main thread:
#0 git_odb_mempack_oidmap_clear libgit2/src/libgit2/odb_mempack.c:31:1
#1 git_mempack_reset libgit2/src/libgit2/odb_mempack.c:179:2
#2 <git2::mempack::Mempack>::reset
Under AddressSanitizer the same program failed in 6 runs of 6: four with
attempting double-free, two with leaked objects.
Possible fix
A borrow-based fix in the wrapper is not enough, because Repository::odb() can hand out several
Odb handles to the same git_odb. Options are to make Mempack::reset and Mempack::dump
unsafe with the requirement that the odb is not used concurrently, or to add a lock to
libgit2's mempack backend.
Found by Crustify, an experimental
UB/soundness auditing agent developed at UC Berkeley and running on Claude Opus 5.5, then
manually reviewed and independently reproduced.
- Lenguaje dominante
- Rust
- Estrellas
- 2.1k
- Forks
- 470
- Merge medio
- 2 d 17 h
- PR fusionados (30 d)
- 18
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-lang/git2-rs
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 messagePosiblemente ocupada @shivampwm2020 la tomó hace 43 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
Todos los issues de rust-lang/git2-rs
Issues similares
-
bug P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Windows microphone listing treats words in a device name as DirectShow labelsPosiblemente ocupada @Sujal-chaudhary la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
clipy-recorder/clipy#447 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
nightly-cleanup
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
max-sixty/worktrunk#4939 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursAbiertoflaky
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
stacks-network/stacks-core#7918 · 1 comentario ·
Los mantenedores suelen responder en 2 días