Skip to content

Commit

Permalink
Ensure that we remove the cleanup hook when envs are GC'ed, addressin…
Browse files Browse the repository at this point in the history
…g CI test failure from parcel-bundler/parcel#7979
  • Loading branch information
kriszyp committed Apr 21, 2022
1 parent a379a37 commit 31b5c6d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "lmdb",
"author": "Kris Zyp",
"version": "2.3.3",
"version": "2.3.4",
"description": "Simple, efficient, scalable, high-performance LMDB interface",
"license": "MIT",
"repository": {
Expand Down
7 changes: 4 additions & 3 deletions src/env.cpp
Expand Up @@ -198,11 +198,12 @@ Napi::Value EnvWrap::open(const CallbackInfo& info) {
#endif
}

rc = this->openEnv(flags, jsFlags, (const char*)pathString.c_str(), (char*) keyBuffer, compression, maxDbs, maxReaders, mapSize, pageSize, encryptKey.empty() ? nullptr : (char*)encryptKey.c_str());
rc = openEnv(flags, jsFlags, (const char*)pathString.c_str(), (char*) keyBuffer, compression, maxDbs, maxReaders, mapSize, pageSize, encryptKey.empty() ? nullptr : (char*)encryptKey.c_str());
//delete[] pathBytes;
if (rc < 0)
return throwLmdbError(info.Env(), rc);
napi_add_env_cleanup_hook(info.Env(), cleanup, this);
napiEnv = info.Env();
napi_add_env_cleanup_hook(napiEnv, cleanup, this);
return info.Env().Undefined();
}
int EnvWrap::openEnv(int flags, int jsFlags, const char* path, char* keyBuffer, Compression* compression, int maxDbs,
Expand Down Expand Up @@ -352,6 +353,7 @@ NAPI_FUNCTION(setEnvsPointer) {
void EnvWrap::closeEnv() {
if (!env)
return;
napi_remove_env_cleanup_hook(napiEnv, cleanup, this);
cleanupStrayTxns();
pthread_mutex_lock(envTracking->envsLock);
for (auto envPath = envTracking->envs.begin(); envPath != envTracking->envs.end(); ) {
Expand All @@ -374,7 +376,6 @@ Napi::Value EnvWrap::close(const CallbackInfo& info) {
if (!this->env) {
return throwError(info.Env(), "The environment is already closed.");
}
napi_remove_env_cleanup_hook(info.Env(), cleanup, this);
this->closeEnv();
return info.Env().Undefined();
}
Expand Down
1 change: 1 addition & 0 deletions src/lmdb-js.h
Expand Up @@ -252,6 +252,7 @@ class EnvWrap : public ObjectWrap<EnvWrap> {
// List of open read transactions
std::vector<TxnWrap*> readTxns;
static env_tracking_t* initTracking();
napi_env napiEnv;
// compression settings and space
Compression *compression;

Expand Down

0 comments on commit 31b5c6d

Please sign in to comment.