Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen Anfängerfreundlich
#62 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
79/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
cpp, node.js

Rechercherichtung

Lies src/linux/BTSerialPortBindingServer.cc und die Deklaration von ClientWorker in src/BTSerialPortBindingServer.h; im Issue werden Execute() und der unsichere Aufruf einer Exception identifiziert. Prüfe, wie NAN mit Fehlern umgeht, die von Execute() aus gesetzt werden, und ersetze dann den Aufruf wie gezeigt durch SetErrorMessage(). Bestätige, dass der Fehler den Callback erreicht und der Prozess ohne Bluetooth-Hardware weiterläuft.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
C++
Sterne
205
Forks
56
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus lsongdev/node-bluetooth

Alle Issues in lsongdev/node-bluetooth

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.