Skip to content

Commit

Permalink
On close, abort requests made before forward()
Browse files Browse the repository at this point in the history
For the benefit of `rave-level`.
  • Loading branch information
vweevers committed Mar 20, 2022
1 parent c1631b0 commit f7dcb5e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions guest.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,19 @@ class ManyLevelGuest extends AbstractLevel {
}

_close (cb) {
if (this[kDb]) return this[kDb]._close(cb)

// Even if forward() was used, still need to abort requests made before forward().
this[kExplicitClose] = true
this[kAbortRequests]('Aborted on database close()', 'LEVEL_DATABASE_NOT_OPEN')

if (this[kRpcStream]) {
// kRpcStream could be a socket and emit 'close' with a
// hadError argument. Ignore that argument.
this[kRpcStream].once('close', () => {
eos(this[kRpcStream], () => {
this[kRpcStream] = null
cb()
this._close(cb)
})
this[kRpcStream].destroy()
} else if (this[kDb]) {
// To be safe, use close() not _close().
this[kDb].close(cb)
} else {
this.nextTick(cb)
}
Expand Down

0 comments on commit f7dcb5e

Please sign in to comment.