Skip to content

Commit c909c02

Browse files
committed
GC finalizers may run after env_cleanup_hook, so Detach methods can
be called when the detached target is already closed. So I've removed the precondition of `Detach+` methods and `DecrementPendingWork` from both `Database` and `Transaction` classes.
1 parent 0dc0b96 commit c909c02

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

src/rocksdb/napi/database.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ void Database::AttachSnapshot(napi_env env, uint32_t id, Snapshot* snapshot) {
139139
}
140140

141141
void Database::DetachSnapshot(napi_env env, uint32_t id) {
142-
assert(!hasClosed_);
143142
snapshots_.erase(id);
144143
DecrementPendingWork(env);
145144
}
@@ -151,7 +150,6 @@ void Database::AttachIterator(napi_env env, uint32_t id, Iterator* iterator) {
151150
}
152151

153152
void Database::DetachIterator(napi_env env, uint32_t id) {
154-
assert(!hasClosed_);
155153
iterators_.erase(id);
156154
DecrementPendingWork(env);
157155
}
@@ -164,7 +162,6 @@ void Database::AttachTransaction(napi_env env, uint32_t id,
164162
}
165163

166164
void Database::DetachTransaction(napi_env env, uint32_t id) {
167-
assert(!hasClosed_);
168165
transactions_.erase(id);
169166
DecrementPendingWork(env);
170167
}
@@ -175,7 +172,6 @@ void Database::IncrementPendingWork(napi_env env) {
175172
}
176173

177174
void Database::DecrementPendingWork(napi_env env) {
178-
assert(!hasClosed_);
179175
napi_reference_unref(env, ref_, &pendingWork_);
180176
// If the `closeWorker_` is set, then the closing operation
181177
// is waiting until all pending work is completed

src/rocksdb/napi/index.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static void env_cleanup_hook(void* arg) {
4848
std::map<uint32_t, Iterator*>::iterator iterator_it;
4949
for (iterator_it = iterators.begin(); iterator_it != iterators.end();
5050
++iterator_it) {
51-
iterator_it->second->Close();
51+
auto iterator = iterator_it->second;
52+
iterator->Close();
5253
}
5354
std::map<uint32_t, Transaction*> transactions = database->transactions_;
5455
std::map<uint32_t, Transaction*>::iterator transaction_it;
@@ -69,7 +70,8 @@ static void env_cleanup_hook(void* arg) {
6970
std::map<uint32_t, Snapshot*>::iterator snapshot_it;
7071
for (snapshot_it = snapshots.begin(); snapshot_it != snapshots.end();
7172
++snapshot_it) {
72-
snapshot_it->second->Release();
73+
auto snapshot = snapshot_it->second;
74+
snapshot->Release();
7375
}
7476
database->Close();
7577
}

src/rocksdb/napi/transaction.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ void Transaction::AttachIterator(napi_env env, uint32_t id,
133133
}
134134

135135
void Transaction::DetachIterator(napi_env env, uint32_t id) {
136-
assert(!hasCommitted_ && !hasRollbacked_);
137136
iterators_.erase(id);
138137
DecrementPendingWork(env);
139138
}
@@ -144,7 +143,6 @@ void Transaction::IncrementPendingWork(napi_env env) {
144143
}
145144

146145
void Transaction::DecrementPendingWork(napi_env env) {
147-
assert(!hasCommitted_ && !hasRollbacked_);
148146
napi_reference_unref(env, ref_, &pendingWork_);
149147
// If the `closeWorker_` is set, then the closing operation
150148
// is waiting until all pending work is completed

0 commit comments

Comments
 (0)