You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 1, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 1, 2026. It is now read-only.
The culprit seems to be the HasInstance method of Database which is called in Statement::Statement. The constructor that it's checking against isn't context-specific. The issue is fixed when the HasInstance check is removed. I'm not sure how it can be replaced with a context-aware version.
I'm using threads.js with sqlite3 (through knex) inside a worker thread and it's working fine for me so far.
I had a similar error message when using sqlite3 < v5 and Nodejs 14.
I came across the issue on FreeBSD when running an application that uses worker threads, which worked fine on my Mac. I had to put the db.prepare in a loop so that it would also trigger on macOS. So it seems that you can get away with it (especially if you only use sqlite3 in one thread), but I believe there is still a bug here. What happens when you run the code snippet above?
The code above crashes on my macOS development system. The issue is the following Database declaration in database.h:
static Napi::FunctionReference constructor;
Static data like this is not supported in a multi-threaded environment
Multi-threaded support is a fairly recent addition to N-API. I've been able to address this issue on my development system using the napi_set_instance_data and napi_get_instance_data API calls to associate a unique constructor value with each thread environment.
These API calls are are implemented in N-APi version 6 and available in Node.js v10.20.0+, v12.8.0+, and v14.0.0+. They are still marked as experimental in the N-API documentation but I've been able to access them without the NAPI_EXPERIMENTAL flag.
Activity
mightypenguin commentedon Jul 31, 2020
I'm using threads.js with sqlite3 (through knex) inside a worker thread and it's working fine for me so far.
I had a similar error message when using sqlite3 < v5 and Nodejs 14.
mohd-akram commentedon Jul 31, 2020
I came across the issue on FreeBSD when running an application that uses worker threads, which worked fine on my Mac. I had to put the
db.preparein a loop so that it would also trigger on macOS. So it seems that you can get away with it (especially if you only use sqlite3 in one thread), but I believe there is still a bug here. What happens when you run the code snippet above?jschlight commentedon Aug 2, 2020
The code above crashes on my macOS development system. The issue is the following
Databasedeclaration indatabase.h:static Napi::FunctionReference constructor;Static data like this is not supported in a multi-threaded environment
Multi-threaded support is a fairly recent addition to N-API. I've been able to address this issue on my development system using the
napi_set_instance_dataandnapi_get_instance_dataAPI calls to associate a uniqueconstructorvalue with each thread environment.These API calls are are implemented in N-APi version 6 and available in Node.js v10.20.0+, v12.8.0+, and v14.0.0+. They are still marked as experimental in the N-API documentation but I've been able to access them without the
NAPI_EXPERIMENTALflag.Add fuzzing test
2736 owner and contract totals accounting keys (#2737)