Possible crash: `Nan::ThrowError` called from `ClientWorker::Execute()`, which runs on the libuv threadpool
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
- Bereich
- backend, embedded-iot
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
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus lsongdev/node-bluetooth
-
bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
lsongdev/node-bluetooth#61 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 25/100
lsongdev/node-bluetooth#60 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
lsongdev/node-bluetooth#57 · 1 Kommentar · 2 Reaktionen ·
-
Maintenance status?Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 10/100
lsongdev/node-bluetooth#55 · 8 Kommentare ·
-
Battery status?Offen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 20/100
lsongdev/node-bluetooth#54 · 1 Kommentar ·
Alle Issues in lsongdev/node-bluetooth
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
leanprover/lean4#15683 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
touhouworldcup/thprac#414 ·