Skip to content

Commit f7dcb5e

Browse files
committed
On close, abort requests made before forward()
For the benefit of `rave-level`.
1 parent c1631b0 commit f7dcb5e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

guest.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,19 +307,19 @@ class ManyLevelGuest extends AbstractLevel {
307307
}
308308

309309
_close (cb) {
310-
if (this[kDb]) return this[kDb]._close(cb)
311-
310+
// Even if forward() was used, still need to abort requests made before forward().
312311
this[kExplicitClose] = true
313312
this[kAbortRequests]('Aborted on database close()', 'LEVEL_DATABASE_NOT_OPEN')
314313

315314
if (this[kRpcStream]) {
316-
// kRpcStream could be a socket and emit 'close' with a
317-
// hadError argument. Ignore that argument.
318-
this[kRpcStream].once('close', () => {
315+
eos(this[kRpcStream], () => {
319316
this[kRpcStream] = null
320-
cb()
317+
this._close(cb)
321318
})
322319
this[kRpcStream].destroy()
320+
} else if (this[kDb]) {
321+
// To be safe, use close() not _close().
322+
this[kDb].close(cb)
323323
} else {
324324
this.nextTick(cb)
325325
}

0 commit comments

Comments
 (0)