Possible crash: `Nan::ThrowError` called from `ClientWorker::Execute()`, which runs on the libuv threadpool
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 79/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- cpp, node.js
- Domínio
- backend, embedded-iot
Direção de pesquisa
Leia src/linux/BTSerialPortBindingServer.cc e a declaração de ClientWorker em src/BTSerialPortBindingServer.h; a issue identifica Execute() e a chamada insegura à exceção. Verifique como o NAN trata erros definidos a partir de Execute() e, em seguida, substitua a chamada por SetErrorMessage(), como mostrado. Confirme que o erro chega ao callback e que o processo continua funcionando sem exigir hardware Bluetooth.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- C++
- Estrelas
- 205
- Forks
- 56
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de lsongdev/node-bluetooth
-
bug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
lsongdev/node-bluetooth#61 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 25/100
lsongdev/node-bluetooth#60 ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 30/100
lsongdev/node-bluetooth#57 · 1 comentário · 2 reações ·
-
Maintenance status?Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 10/100
lsongdev/node-bluetooth#55 · 8 comentários ·
-
Battery status?Aberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 20/100
lsongdev/node-bluetooth#54 · 1 comentário ·
Todas as issues de lsongdev/node-bluetooth
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
Mantenedores costumam responder em até 4 dias
-
nth_root does not restore the rounding mode and can return an upper bound below the true rootAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
scanaislop/aislop#482 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
EchoTools/nevr-runtime#547 ·
Mantenedores costumam responder em até 1 dia
-
1 type: problem 2 scope: firmware 3 good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
SpaceTeam/STS1_COBC_SW#511 ·