nodejs / nodejs/node

diagnostics_channel: Channel::binding_data_ dangles after environment cleanup, crashing node:sqlite at exit

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

Chưa có ai nhận issue này.

Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

Version

v27.0.0-pre (2dfdb6a4206)

Platform
Darwin 25.6.0 arm64
Subsystem

diagnostics_channel, sqlite

What steps will reproduce the bug?

Channel holds its BindingData as a raw pointer that is never cleared, so any native holder that outlives environment cleanup reads a destroyed object. Here's a replication case using node:sqlite:

const dc = require('node:diagnostics_channel');
const { DatabaseSync } = require('node:sqlite');

dc.subscribe('sqlite.db.query', () => {});

const db = new DatabaseSync(':memory:');
db.exec('CREATE TABLE t(x)');
const ins = db.prepare('INSERT INTO t VALUES (?)');
for (let i = 0; i < 200; i++) ins.run(i);

// Start iterating and abandon it: the statement stays mid-step, so the
// finalize that happens at teardown fires SQLite's profile callback.
const it = db.prepare('SELECT * FROM t').iterate();
it.next();
globalThis.keepAlive = { db, it };
console.log('reached end of script');
How often does it reproduce? Is there a required condition?

Three conditions are required (all included in the example above):

  1. A subscriber on sqlite.db.query, so the SQLite profile hook is installed.
  2. A statement left mid-step at exit, so that the finalize during teardown has a started statement to profile.
  3. No explicit close(), so the statement is finalized by the destructor chain after Environment::RunCleanup() rather than before it.
What is the expected behavior? Why is that the expected behavior?

Exiting a process that used node:sqlite with a sqlite.db.query subscriber
shouldn't crash.

What do you see instead?

SIGSEGV, exit 139, after the script has finished.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Hướng nghiên cứu

Trước tiên, hãy chạy bản tái hiện được cung cấp của node:diagnostics_channel và node:sqlite, sau đó truy vết Channel::binding_data_ qua Environment::RunCleanup() và callback profile của SQLite. Xác nhận bản sửa với cùng kịch bản thoát, bao gồm một statement còn dở giữa một bước mà không gọi close() một cách rõ ràng, và đảm bảo tiến trình thoát mà không có SIGSEGV.

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

Đánh giá

Công nghệ
javascript, node.js, sqlite
Lĩnh vực
backend, databases, observability
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

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.