Wrap all async JS callbacks, help avoid possible race #3569

This commit is contained in:
Lovell Fuller 2023-03-01 12:41:11 +00:00
parent 0063df4d4f
commit 4ec883eaa0
4 changed files with 8 additions and 5 deletions

View File

@ -53,6 +53,9 @@ Requires libvips v8.14.0
[#3556](https://github.com/lovell/sharp/pull/3556)
[@janaz](https://github.com/janaz)
* Ensure all async JS callbacks are wrapped to help avoid possible race condition.
[#3569](https://github.com/lovell/sharp/issues/3569)
## v0.31 - *eagle*
Requires libvips v8.13.3

View File

@ -145,7 +145,7 @@ class MetadataWorker : public Napi::AsyncWorker {
// Handle warnings
std::string warning = sharp::VipsWarningPop();
while (!warning.empty()) {
debuglog.Call({ Napi::String::New(env, warning) });
debuglog.MakeCallback(Receiver().Value(), { Napi::String::New(env, warning) });
warning = sharp::VipsWarningPop();
}

View File

@ -1175,7 +1175,7 @@ class PipelineWorker : public Napi::AsyncWorker {
// Handle warnings
std::string warning = sharp::VipsWarningPop();
while (!warning.empty()) {
debuglog.Call({ Napi::String::New(env, warning) });
debuglog.MakeCallback(Receiver().Value(), { Napi::String::New(env, warning) });
warning = sharp::VipsWarningPop();
}
@ -1251,7 +1251,7 @@ class PipelineWorker : public Napi::AsyncWorker {
// Decrement processing task counter
g_atomic_int_dec_and_test(&sharp::counterProcess);
Napi::Number queueLength = Napi::Number::New(env, static_cast<double>(sharp::counterQueue));
queueListener.Call(Receiver().Value(), { queueLength });
queueListener.MakeCallback(Receiver().Value(), { queueLength });
}
private:
@ -1681,7 +1681,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
// Increment queued task counter
g_atomic_int_inc(&sharp::counterQueue);
Napi::Number queueLength = Napi::Number::New(info.Env(), static_cast<double>(sharp::counterQueue));
queueListener.Call(info.This(), { queueLength });
queueListener.MakeCallback(info.This(), { queueLength });
return info.Env().Undefined();
}

View File

@ -106,7 +106,7 @@ class StatsWorker : public Napi::AsyncWorker {
// Handle warnings
std::string warning = sharp::VipsWarningPop();
while (!warning.empty()) {
debuglog.Call({ Napi::String::New(env, warning) });
debuglog.MakeCallback(Receiver().Value(), { Napi::String::New(env, warning) });
warning = sharp::VipsWarningPop();
}