Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#2,295 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@atontini đang làm issue này rồi.

Từ ngày 19/10/2026.

  • #2296 của @atontini — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust, sql
Lĩnh vực
databases

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C
Star
17.3k
Fork
545
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tursodatabase/libsql

Tất cả issue của tursodatabase/libsql

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.