Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#2,295 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@atontini ya está trabajando en esto.

Desde el 19/10/2026.

  • #2296 de @atontini — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust, sql
Área
databases

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C
Estrellas
17.3k
Forks
545
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tursodatabase/libsql

Todos los issues de tursodatabase/libsql

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.