Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Rust: final update-hook closure and captures leak on connection close

Aperta
#2,295 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@atontini ci sta già lavorando.

Dal 19/10/2026.

  • #2296 di @atontini — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust, sql
Ambito
databases

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tursodatabase/libsql

Tutte le issue di tursodatabase/libsql

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.