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

Possible crash: `Nan::ThrowError` called from `ClientWorker::Execute()`, which runs on the libuv threadpool

Đang mở Phù hợp với người mới
#62 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.

Đá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

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 lsongdev/node-bluetooth

Tất cả issue của lsongdev/node-bluetooth

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.