Rust: final update-hook closure and captures leak on connection close
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 58/100
Direzione di ricerca
Start in libsql/src/local/connection.rs and trace Connection::add_update_hook alongside disconnect and the connection or statement ownership paths. Check how replacement handles wrapper-owned callback contexts and how outstanding clones and prepared statements keep the connection alive. Reproduce with the public API example; done means the final callback is released when the last owner closes, without reclaiming a context installed through the raw handle.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Registering an update hook through the Rust Connection::add_update_hook API leaks the final callback allocation and everything captured by its closure when the local connection closes.
In libsql/src/local/connection.rs, registration uses Box::leak(Container { cb }). The previous context is reclaimed on replacement, but disconnect only calls sqlite3_close_v2. SQLite's update-hook API has no context destructor, so the final allocation is never reclaimed.
Reproduction using the public API:
let db = libsql::Builder::new_local(":memory:").build().await?;
let conn = db.connect()?;
let captured = std::sync::Arc::new(());
let weak = std::sync::Arc::downgrade(&captured);
conn.add_update_hook(Box::new(move |_, _, _, _| { let _ = &captured; }))?;
drop(conn);
assert!(weak.upgrade().is_none()); // fails: callback still owns captured
Expected: release the callback once the final connection/statement owner closes, while keeping it alive for outstanding clones and prepared statements. Replacement should release only contexts allocated by the Rust wrapper, rather than assuming a context installed through the raw handle is a Container.
Observed in upstream main. Originally identified during a Tokensave audit: https://github.com/aovestdipaperino/tokensave/issues/697#issuecomment-6260552467 and https://github.com/aovestdipaperino/tokensave/pull/705. That downstream patch was closed because Tokensave does not currently register update hooks; the ownership bug belongs upstream.
- Lingua principale
- C
- Stelle
- 17.3k
- Fork
- 545
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun 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 tursodatabase/libsql
-
Rust local Row::get_value truncates embedded NUL TEXT and panics on malformed UTF-8 (0.9.30)Forse già presa @Sanjays2402 l’ha presa 9 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
tursodatabase/libsql#2285 ·
-
libsql-ffi: broken builds under Nix on macOSForse già presa @frectonz l’ha presa 59 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
tursodatabase/libsql#2275 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
tursodatabase/libsql#2226 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
tursodatabase/libsql#1925 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
tursodatabase/libsql#1892 ·
Tutte le issue di tursodatabase/libsql
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
valkey-io/valkey#4979 · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
colbymchenry/codegraph#2770 ·
I maintainer di solito rispondono entro 1 giorno
-
area/ysql kind/enhancement priority/medium status/awaiting-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
yugabyte/yugabyte-db#35578 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
test_announce_and_connect_via_dns binds a fixed port that other tests' nodes can be handedForse già presa @ksedgwic l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
ElementsProject/lightning#9642 ·
I maintainer di solito rispondono entro 2 giorni