Possible crash: `Nan::ThrowError` called from `ClientWorker::Execute()`, which runs on the libuv threadpool
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 79/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- cpp, node.js
- 領域
- backend, embedded-iot
研究方向
閱讀 src/linux/BTSerialPortBindingServer.cc 以及 src/BTSerialPortBindingServer.h 中 ClientWorker 的宣告;issue 指出了 Execute() 和不安全的例外呼叫。檢查 NAN 如何處理從 Execute() 設定的錯誤,接著依照所示將呼叫替換為 SetErrorMessage()。確認錯誤能傳遞至 callback,且程序在沒有 Bluetooth 硬體的情況下仍能繼續執行。
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- C++
- 星號
- 205
- 分支
- 56
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
lsongdev/node-bluetooth 的其他 Issue
-
bug
難度 4/5 3-5 天 新手友好度 45/100
lsongdev/node-bluetooth#61 ·
-
難度 3/5 1-2 天 新手友好度 25/100
lsongdev/node-bluetooth#60 ·
-
難度 4/5 3-5 天 新手友好度 30/100
lsongdev/node-bluetooth#57 · 1 則留言 · 2 個 reaction ·
-
難度 1/5 1 小時以內 新手友好度 10/100
lsongdev/node-bluetooth#55 · 8 則留言 ·
-
Battery status?未關閉
難度 5/5 一週以上 新手友好度 20/100
lsongdev/node-bluetooth#54 · 1 則留言 ·
查看 lsongdev/node-bluetooth 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 70/100
FriendsofECCE/ECCE#336 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 66/100
bitcoin-core/gui-qml#1030 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
tesseract-robotics/tesseract#1384 ·
-
難度 2/5 1-3 小時 新手友好度 62/100
NVIDIA/nccl-extensions#26 ·