Skip to content

Commit

Permalink
Wrap all async JS callbacks, help avoid possible race #3569
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Mar 1, 2023
1 parent 0063df4 commit 4ec883e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion src/stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 4ec883e

Please sign in to comment.