Rust: final update-hook closure and captures leak on connection close
Đá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
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
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tursodatabase/libsql
-
bottomless: finished S3 upload tasks are never reaped, so sqld memory grows by ~10 KB per WAL batchCó thể đã có người làm @pavanmanishd đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
tursodatabase/libsql#2298 · 1 bình luận ·
-
Rust local Row::get_value truncates embedded NUL TEXT and panics on malformed UTF-8 (0.9.30)Có thể đã có người làm @Sanjays2402 đã nhận 11 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
tursodatabase/libsql#2285 ·
-
libsql-ffi: broken builds under Nix on macOSCó thể đã có người làm @frectonz đã nhận 61 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
tursodatabase/libsql#2275 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
tursodatabase/libsql#2226 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
tursodatabase/libsql#1925 ·
Tất cả issue của tursodatabase/libsql
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 93/100
webarkit/WebARKitLib#107 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
polhenarejos/pico-fido#302 ·
-
[BUG] Out-of-range negative slice end returns the whole stringCó thể đã có người làm @Don-Yin đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
fastfetch-cli/fastfetch#2668 ·
Maintainer thường phản hồi trong vòng 1 ngày