Skip to content

Commit c9caae4

Browse files
authored
Fix worker threads crash (#1367)
1 parent 6e250c6 commit c9caae4

File tree

11 files changed

+57
-56
lines changed

11 files changed

+57
-56
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ local.env
2626
.eslintrc.js
2727
setup.sh
2828
/build-tmp-napi-v3
29+
/build-tmp-napi-v6

.travis.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,63 +75,63 @@ matrix:
7575
# electron Linux
7676
- os: linux
7777
compiler: clang
78-
env: NODE_VERSION="12" ELECTRON_VERSION="8.2.0"
78+
env: NODE_VERSION="12.13.0" ELECTRON_VERSION="8.2.0"
7979
dist: trusty
8080
addons:
8181
apt:
8282
sources: [ 'ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5', 'gcc-multilib', 'g++-multilib', 'libsqlite3-dev:i386' ]
8383
packages: [ 'clang-3.5', 'libstdc++-4.9-dev']
8484
- os: linux
8585
compiler: clang
86-
env: NODE_VERSION="12" ELECTRON_VERSION="8.1.0"
86+
env: NODE_VERSION="12.13.0" ELECTRON_VERSION="8.1.0"
8787
dist: trusty
8888
addons:
8989
apt:
9090
sources: [ 'ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5', 'gcc-multilib', 'g++-multilib', 'libsqlite3-dev:i386' ]
9191
packages: [ 'clang-3.5', 'libstdc++-4.9-dev']
9292
- os: linux
9393
compiler: clang
94-
env: NODE_VERSION="12" ELECTRON_VERSION="8.0.0"
94+
env: NODE_VERSION="12.13.0" ELECTRON_VERSION="8.0.0"
9595
dist: trusty
9696
addons:
9797
apt:
9898
sources: [ 'ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5', 'gcc-multilib', 'g++-multilib', 'libsqlite3-dev:i386' ]
9999
packages: [ 'clang-3.5', 'libstdc++-4.9-dev']
100100
- os: linux
101101
compiler: clang
102-
env: NODE_VERSION="12" ELECTRON_VERSION="7.2.0"
102+
env: NODE_VERSION="12.8.1" ELECTRON_VERSION="7.2.0"
103103
dist: trusty
104104
addons:
105105
apt:
106106
sources: [ 'ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5', 'gcc-multilib', 'g++-multilib', 'libsqlite3-dev:i386' ]
107107
packages: [ 'clang-3.5', 'libstdc++-4.9-dev']
108108
- os: linux
109109
compiler: clang
110-
env: NODE_VERSION="12" ELECTRON_VERSION="7.1.0"
110+
env: NODE_VERSION="12.8.1" ELECTRON_VERSION="7.1.0"
111111
dist: trusty
112112
addons:
113113
apt:
114114
sources: [ 'ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5', 'gcc-multilib', 'g++-multilib', 'libsqlite3-dev:i386' ]
115115
packages: [ 'clang-3.5', 'libstdc++-4.9-dev']
116116
- os: linux
117117
compiler: clang
118-
env: NODE_VERSION="12" ELECTRON_VERSION="7.0.0"
118+
env: NODE_VERSION="12.8.1" ELECTRON_VERSION="7.0.0"
119119
dist: trusty
120120
addons:
121121
apt:
122122
sources: [ 'ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5', 'gcc-multilib', 'g++-multilib', 'libsqlite3-dev:i386' ]
123123
packages: [ 'clang-3.5', 'libstdc++-4.9-dev']
124124
- os: linux
125125
compiler: clang
126-
env: NODE_VERSION="12" ELECTRON_VERSION="6.1.0"
126+
env: NODE_VERSION="12.4.0" ELECTRON_VERSION="6.1.0"
127127
dist: trusty
128128
addons:
129129
apt:
130130
sources: [ 'ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5', 'gcc-multilib', 'g++-multilib', 'libsqlite3-dev:i386' ]
131131
packages: [ 'clang-3.5', 'libstdc++-4.9-dev']
132132
- os: linux
133133
compiler: clang
134-
env: NODE_VERSION="12" ELECTRON_VERSION="6.0.0"
134+
env: NODE_VERSION="12.4.0" ELECTRON_VERSION="6.0.0"
135135
dist: trusty # needed for libc6 / 'version `GLIBC_2.17` not found' error on precise
136136
addons:
137137
apt:
@@ -140,28 +140,28 @@ matrix:
140140
# electron MacOs
141141
- os: osx
142142
compiler: clang
143-
env: NODE_VERSION="12" ELECTRON_VERSION="8.2.0"
143+
env: NODE_VERSION="12.13.0" ELECTRON_VERSION="8.2.0"
144144
- os: osx
145145
compiler: clang
146-
env: NODE_VERSION="12" ELECTRON_VERSION="8.1.0"
146+
env: NODE_VERSION="12.13.0" ELECTRON_VERSION="8.1.0"
147147
- os: osx
148148
compiler: clang
149-
env: NODE_VERSION="12" ELECTRON_VERSION="8.0.0"
149+
env: NODE_VERSION="12.13.0" ELECTRON_VERSION="8.0.0"
150150
- os: osx
151151
compiler: clang
152-
env: NODE_VERSION="12" ELECTRON_VERSION="7.2.0"
152+
env: NODE_VERSION="12.8.1" ELECTRON_VERSION="7.2.0"
153153
- os: osx
154154
compiler: clang
155-
env: NODE_VERSION="12" ELECTRON_VERSION="7.1.0"
155+
env: NODE_VERSION="12.8.1" ELECTRON_VERSION="7.1.0"
156156
- os: osx
157157
compiler: clang
158-
env: NODE_VERSION="12" ELECTRON_VERSION="7.0.0"
158+
env: NODE_VERSION="12.8.1" ELECTRON_VERSION="7.0.0"
159159
- os: osx
160160
compiler: clang
161-
env: NODE_VERSION="12" ELECTRON_VERSION="6.1.0"
161+
env: NODE_VERSION="12.4.0" ELECTRON_VERSION="6.1.0"
162162
- os: osx
163163
compiler: clang
164-
env: NODE_VERSION="12" ELECTRON_VERSION="6.0.0"
164+
env: NODE_VERSION="12.4.0" ELECTRON_VERSION="6.0.0"
165165

166166
env:
167167
global:

appveyor.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,88 +21,88 @@ environment:
2121
- nodejs_version: 14
2222
platform: x86
2323
# electron
24-
- nodejs_version: 12
24+
- nodejs_version: 12.13.0
2525
platform: x64
2626
NODE_RUNTIME: electron
2727
NODE_RUNTIME_VERSION: 8.2.0
2828
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
29-
- nodejs_version: 12
29+
- nodejs_version: 12.13.0
3030
platform: x86
3131
NODE_RUNTIME: electron
3232
NODE_RUNTIME_VERSION: 8.2.0
3333
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
34-
- nodejs_version: 12
34+
- nodejs_version: 12.13.0
3535
platform: x64
3636
NODE_RUNTIME: electron
3737
NODE_RUNTIME_VERSION: 8.1.0
3838
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
39-
- nodejs_version: 12
39+
- nodejs_version: 12.13.0
4040
platform: x86
4141
NODE_RUNTIME: electron
4242
NODE_RUNTIME_VERSION: 8.1.0
4343
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
44-
- nodejs_version: 12
44+
- nodejs_version: 12.13.0
4545
platform: x64
4646
NODE_RUNTIME: electron
4747
NODE_RUNTIME_VERSION: 8.0.0
4848
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
49-
- nodejs_version: 12
49+
- nodejs_version: 12.13.0
5050
platform: x86
5151
NODE_RUNTIME: electron
5252
NODE_RUNTIME_VERSION: 8.0.0
5353
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
54-
- nodejs_version: 12
54+
- nodejs_version: 12.8.1
5555
platform: x64
5656
NODE_RUNTIME: electron
5757
NODE_RUNTIME_VERSION: 7.2.0
5858
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
59-
- nodejs_version: 12
59+
- nodejs_version: 12.8.1
6060
platform: x86
6161
NODE_RUNTIME: electron
6262
NODE_RUNTIME_VERSION: 7.2.0
6363
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
64-
- nodejs_version: 12
64+
- nodejs_version: 12.8.1
6565
platform: x64
6666
NODE_RUNTIME: electron
6767
NODE_RUNTIME_VERSION: 7.1.0
6868
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
69-
- nodejs_version: 12
69+
- nodejs_version: 12.8.1
7070
platform: x86
7171
NODE_RUNTIME: electron
7272
NODE_RUNTIME_VERSION: 7.1.0
7373
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
74-
- nodejs_version: 12
74+
- nodejs_version: 12.8.1
7575
platform: x64
7676
NODE_RUNTIME: electron
7777
NODE_RUNTIME_VERSION: 7.0.0
7878
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
79-
- nodejs_version: 12
79+
- nodejs_version: 12.8.1
8080
platform: x86
8181
NODE_RUNTIME: electron
8282
NODE_RUNTIME_VERSION: 7.0.0
8383
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
84-
- nodejs_version: 12
84+
- nodejs_version: 12.4.0
8585
platform: x64
8686
NODE_RUNTIME: electron
8787
NODE_RUNTIME_VERSION: 6.1.0
8888
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
89-
- nodejs_version: 12
89+
- nodejs_version: 12.4.0
9090
platform: x86
9191
NODE_RUNTIME: electron
9292
NODE_RUNTIME_VERSION: 6.1.0
9393
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
94-
- nodejs_version: 12
94+
- nodejs_version: 12.4.0
9595
platform: x64
9696
NODE_RUNTIME: electron
9797
NODE_RUNTIME_VERSION: 6.0.0
9898
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
99-
- nodejs_version: 12
99+
- nodejs_version: 12.4.0
100100
platform: x86
101101
NODE_RUNTIME: electron
102102
NODE_RUNTIME_VERSION: 6.0.0
103103
TOOLSET_ARGS: --dist-url=https://electronjs.org/headers
104104

105-
os: Visual Studio 2015
105+
image: Visual Studio 2017
106106

107107

108108
install:

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"remote_path": "./{name}/v{version}/{toolset}/",
1515
"package_name": "napi-v{napi_build_version}-{platform}-{arch}.tar.gz",
1616
"napi_versions": [
17-
3
17+
3,
18+
6
1819
]
1920
},
2021
"contributors": [
@@ -40,7 +41,7 @@
4041
"url": "git://github.com/mapbox/node-sqlite3.git"
4142
},
4243
"dependencies": {
43-
"node-addon-api": "2.0.0",
44+
"node-addon-api": "^3.0.0",
4445
"node-pre-gyp": "^0.11.0"
4546
},
4647
"devDependencies": {

scripts/build-appveyor.bat

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ SET EL=0
44

55
ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %~f0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66

7-
IF /I "%msvs_toolset%"=="" ECHO msvs_toolset unset, defaulting to 14 && SET msvs_toolset=14
8-
IF /I "%msvs_version%"=="" ECHO msvs_version unset, defaulting to 2015 && SET msvs_version=2015
7+
IF /I "%msvs_version%"=="" ECHO msvs_version unset, defaulting to 2017 && SET msvs_version=2017
98

109
SET PATH=%CD%;%PATH%
11-
IF "%msvs_toolset%"=="12" SET msvs_version=2013
1210
IF NOT "%NODE_RUNTIME%"=="" SET "TOOLSET_ARGS=%TOOLSET_ARGS% --runtime=%NODE_RUNTIME%"
1311
IF NOT "%NODE_RUNTIME_VERSION%"=="" SET "TOOLSET_ARGS=%TOOLSET_ARGS% --target=%NODE_RUNTIME_VERSION%"
1412

1513
ECHO APPVEYOR^: %APPVEYOR%
1614
ECHO nodejs_version^: %nodejs_version%
1715
ECHO platform^: %platform%
18-
ECHO msvs_toolset^: %msvs_toolset%
1916
ECHO msvs_version^: %msvs_version%
2017
ECHO TOOLSET_ARGS^: %TOOLSET_ARGS%
2118

2219
ECHO activating VS command prompt
2320
:: NOTE this call makes the x64 -> X64
24-
IF /I "%platform%"=="x64" ECHO x64 && CALL "C:\Program Files (x86)\Microsoft Visual Studio %msvs_toolset%.0\VC\vcvarsall.bat" amd64
25-
IF /I "%platform%"=="x86" ECHO x86 && CALL "C:\Program Files (x86)\Microsoft Visual Studio %msvs_toolset%.0\VC\vcvarsall.bat" x86
21+
IF /I "%platform%"=="x64" ECHO x64 && CALL "C:\Program Files (x86)\Microsoft Visual Studio\%msvs_version%\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
22+
IF /I "%platform%"=="x86" ECHO x86 && CALL "C:\Program Files (x86)\Microsoft Visual Studio\%msvs_version%\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
2623
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
2724

2825
ECHO using compiler^: && CALL cl

src/backup.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
using namespace node_sqlite3;
99

10-
Napi::FunctionReference Backup::constructor;
11-
12-
1310
Napi::Object Backup::Init(Napi::Env env, Napi::Object exports) {
1411
Napi::HandleScope scope(env);
1512

@@ -24,9 +21,6 @@ Napi::Object Backup::Init(Napi::Env env, Napi::Object exports) {
2421
InstanceAccessor("retryErrors", &Backup::RetryErrorGetter, &Backup::RetryErrorSetter),
2522
});
2623

27-
constructor = Napi::Persistent(t);
28-
constructor.SuppressDestruct();
29-
3024
exports.Set("Backup", t);
3125
return exports;
3226
}

src/backup.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ namespace node_sqlite3 {
9393
*/
9494
class Backup : public Napi::ObjectWrap<Backup> {
9595
public:
96-
static Napi::FunctionReference constructor;
97-
9896
static Napi::Object Init(Napi::Env env, Napi::Object exports);
9997

10098
struct Baton {

src/database.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#include <string.h>
2+
#include <napi.h>
23

34
#include "macros.h"
45
#include "database.h"
56
#include "statement.h"
67

78
using namespace node_sqlite3;
89

10+
#if NAPI_VERSION < 6
911
Napi::FunctionReference Database::constructor;
12+
#endif
1013

1114
Napi::Object Database::Init(Napi::Env env, Napi::Object exports) {
1215
Napi::HandleScope scope(env);
@@ -23,8 +26,14 @@ Napi::Object Database::Init(Napi::Env env, Napi::Object exports) {
2326
InstanceAccessor("open", &Database::OpenGetter, nullptr)
2427
});
2528

29+
#if NAPI_VERSION < 6
2630
constructor = Napi::Persistent(t);
2731
constructor.SuppressDestruct();
32+
#else
33+
Napi::FunctionReference* constructor = new Napi::FunctionReference();
34+
*constructor = Napi::Persistent(t);
35+
env.SetInstanceData<Napi::FunctionReference>(constructor);
36+
#endif
2837

2938
exports.Set("Database", t);
3039
return exports;

src/database.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,23 @@ class Database;
2121

2222
class Database : public Napi::ObjectWrap<Database> {
2323
public:
24+
#if NAPI_VERSION < 6
2425
static Napi::FunctionReference constructor;
26+
#endif
2527
static Napi::Object Init(Napi::Env env, Napi::Object exports);
2628

2729
static inline bool HasInstance(Napi::Value val) {
2830
Napi::Env env = val.Env();
2931
Napi::HandleScope scope(env);
3032
if (!val.IsObject()) return false;
3133
Napi::Object obj = val.As<Napi::Object>();
34+
#if NAPI_VERSION < 6
3235
return obj.InstanceOf(constructor.Value());
36+
#else
37+
Napi::FunctionReference* constructor =
38+
env.GetInstanceData<Napi::FunctionReference>();
39+
return obj.InstanceOf(constructor->Value());
40+
#endif
3341
}
3442

3543
struct Baton {

src/statement.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
using namespace node_sqlite3;
1010

11-
Napi::FunctionReference Statement::constructor;
12-
1311
Napi::Object Statement::Init(Napi::Env env, Napi::Object exports) {
1412
Napi::HandleScope scope(env);
1513

@@ -23,9 +21,6 @@ Napi::Object Statement::Init(Napi::Env env, Napi::Object exports) {
2321
InstanceMethod("finalize", &Statement::Finalize_),
2422
});
2523

26-
constructor = Napi::Persistent(t);
27-
constructor.SuppressDestruct();
28-
2924
exports.Set("Statement", t);
3025
return exports;
3126
}

0 commit comments

Comments
 (0)