Possible crash: `Nan::ThrowError` called from `ClientWorker::Execute()`, which runs on the libuv threadpool
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 79/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ệ
- cpp, node.js
- Lĩnh vực
- backend, embedded-iot
Hướng nghiên cứu
Đọc src/linux/BTSerialPortBindingServer.cc và phần khai báo ClientWorker trong src/BTSerialPortBindingServer.h; issue xác định Execute() và lệnh gọi ngoại lệ không an toàn. Kiểm tra cách NAN xử lý các lỗi được đặt từ Execute(), sau đó thay lệnh gọi bằng SetErrorMessage() như minh họa. Xác nhận lỗi đến được callback và tiến trình vẫn hoạt động mà không cần phần cứng Bluetooth.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Nan::ThrowError called from ClientWorker::Execute(), which runs on the libuv threadpool
BTSerialPortBindingServer::ClientWorker is a Nan::AsyncWorker, so its
Execute() override runs on a libuv threadpool thread rather than the thread
that owns the V8 isolate. It raises a JavaScript exception from there:
// src/linux/BTSerialPortBindingServer.cc
void BTSerialPortBindingServer::ClientWorker::Execute(){
if(mBaton == nullptr){
return Nan::ThrowError("listen_baton_t is null!");
}
Nan::ThrowError reaches v8::Isolate::ThrowException, which may only be
called on the isolate's own thread. The declaration confirms the context:
// src/BTSerialPortBindingServer.h
class ClientWorker : public Nan::AsyncWorker {
void Execute() override;
void HandleOKCallback() override;
};
Reproduction
The behaviour does not depend on Bluetooth hardware; it follows from raising a
V8 exception inside Execute(). A minimal addon with the same shape:
class ThrowingWorker : public Nan::AsyncWorker {
public:
explicit ThrowingWorker(Nan::Callback *cb) : Nan::AsyncWorker(cb) {}
void Execute() override {
return Nan::ThrowError("raised from the worker thread");
}
void HandleOKCallback() override {
Nan::HandleScope scope;
v8::Local<v8::Value> argv[] = { Nan::Null() };
callback->Call(1, argv, async_resource);
}
};
const addon = require('./build/Release/poc.node');
process.on('uncaughtException', e => console.log('[uncaughtException]', e && e.message));
addon.run(() => console.log('[callback] ran'));
setTimeout(() => console.log('[alive] process survived'), 1000);
Node v22.17.1, macOS arm64, nan 2.x:
| worker body | exit code | output |
|---|---|---|
Nan::ThrowError(...) |
139 (SIGSEGV), 5/5 runs | none; the callback never runs |
SetErrorMessage(...) |
0, 3/3 runs | [callback] err = raised from the worker thread, [alive] process survived |
Suggested fix
NAN provides SetErrorMessage() for exactly this: record the message in
Execute() and let NAN deliver it on the loop thread through
HandleErrorCallback().
void BTSerialPortBindingServer::ClientWorker::Execute(){
if(mBaton == nullptr){
- return Nan::ThrowError("listen_baton_t is null!");
+ return SetErrorMessage("listen_baton_t is null!");
}
The existing HandleOKCallback() stays as it is; NAN calls
HandleErrorCallback() instead when an error message has been set, and the
default implementation passes the message to the stored callback as an Error.
- Ngôn ngữ chính
- C++
- Star
- 205
- Fork
- 56
- 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
- Không có Dockerfile hay 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 lsongdev/node-bluetooth
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
lsongdev/node-bluetooth#61 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
lsongdev/node-bluetooth#60 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
lsongdev/node-bluetooth#57 · 1 bình luận · 2 reaction ·
-
Maintenance status?Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 10/100
lsongdev/node-bluetooth#55 · 8 bình luận ·
-
Battery status?Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
lsongdev/node-bluetooth#54 · 1 bình luận ·
Tất cả issue của lsongdev/node-bluetooth
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 76/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
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/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 77/100
ros-navigation/navigation2#6648 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] OTA Requestor accepts reserved provider endpoint 0xFFFFCó thể đã có người làm @Chapoly1305 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
project-chip/connectedhomeip#74742 ·
Maintainer thường phản hồi trong vòng 1 ngày