Skip to content

Commit

Permalink
Fix segfaults when used with worker_threads (#24)
Browse files Browse the repository at this point in the history
* fix: don't use static constructor field with global scope which results in a race condition between worker threads.

* fix: ci pipeline
  • Loading branch information
mariuspod authored Dec 28, 2022
1 parent af2f292 commit c535a69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,17 @@ jobs:
os:
- macos-latest
- ubuntu-latest
- windows-latest
- windows-2019
steps:
- name: Fetch code
uses: actions/checkout@v1
with:
submodules: true

- name: Install dependencies
run: yarn install --ignore-scripts

- name: Build addon
if: runner.os != 'Linux'
run: make build-addon

- name: Build addon
if: runner.os == 'Linux'
run: make build-addon-linux

- name: Get minimal Node.js version from package.json (Linux & macOS)
id: node-version-nix
if: runner.os != 'Windows'
run: echo "::set-output name=version::$(node -p 'require("./package.json").engines.node.match(/(\d.*)$/)[0]')"
run: echo "::set-output name=version::$(node -p 'require("./package.json").engines.node.match(/(\d+)\..*$/)[1]')"

- name: Use Node.js ${{ steps.node-version-nix.outputs.version }} (Linux & macOS)
if: runner.os != 'Windows'
Expand All @@ -46,14 +35,25 @@ jobs:
- name: Get minimal Node.js version from package.json (Windows)
id: node-version-win
if: runner.os == 'Windows'
run: echo "::set-output name=version::$(node -p 'require(\"./package.json\").engines.node.match(/(\d.*)$/)[0]')"
run: echo "::set-output name=version::$(node -p 'require(\"./package.json\").engines.node.match(/(\d+)\..*$/)[1]')"

- name: Use Node.js ${{ steps.node-version-win.outputs.version }} (Windows)
if: runner.os == 'Windows'
uses: actions/setup-node@v1
with:
node-version: ${{ steps.node-version-win.outputs.version }}

- name: Install dependencies
run: yarn install --ignore-scripts

- name: Build addon
if: runner.os != 'Linux'
run: make build-addon

- name: Build addon
if: runner.os == 'Linux'
run: make build-addon-linux

- name: Run tests for addon
run: make test-tap

Expand Down
6 changes: 0 additions & 6 deletions src/addon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class KeccakWrapper : public Napi::ObjectWrap<KeccakWrapper> {

private:
KeccakWidth1600_SpongeInstance sponge;
static Napi::FunctionReference constructor;

Napi::Value Initialize(const Napi::CallbackInfo& info);
Napi::Value Absorb(const Napi::CallbackInfo& info);
Expand All @@ -21,8 +20,6 @@ class KeccakWrapper : public Napi::ObjectWrap<KeccakWrapper> {
Napi::Value Copy(const Napi::CallbackInfo& info);
};

Napi::FunctionReference KeccakWrapper::constructor;

Napi::Object KeccakWrapper::Init(Napi::Env env) {
Napi::Function func =
DefineClass(env,
Expand All @@ -36,9 +33,6 @@ Napi::Object KeccakWrapper::Init(Napi::Env env) {
InstanceMethod("copy", &KeccakWrapper::Copy),
});

constructor = Napi::Persistent(func);
constructor.SuppressDestruct();

return func;
}

Expand Down

0 comments on commit c535a69

Please sign in to comment.