Skip to content

Commit

Permalink
fix: close and destroy overlap (#2068)
Browse files Browse the repository at this point in the history
* fix: close and destroy overlap

* fixup
  • Loading branch information
ronag committed Apr 14, 2023
1 parent 98fa282 commit 7ef4270
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class Client extends DispatcherBase {
async [kClose] () {
return new Promise((resolve) => {
if (!this[kSize]) {
this.destroy(resolve)
resolve(null)
} else {
this[kClosedResolve] = resolve
}
Expand All @@ -338,6 +338,7 @@ class Client extends DispatcherBase {

const callback = () => {
if (this[kClosedResolve]) {
// TODO (fix): Should we error here with ClientDestroyedError?
this[kClosedResolve]()
this[kClosedResolve] = null
}
Expand Down Expand Up @@ -1201,8 +1202,9 @@ function _resume (client, sync) {
return
}

if (client.closed && !client[kSize]) {
client[kDestroy]()
if (client[kClosedResolve] && !client[kSize]) {
client[kClosedResolve]()
client[kClosedResolve] = null
return
}

Expand Down
5 changes: 3 additions & 2 deletions lib/dispatcher-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DispatcherBase extends Dispatcher {
super()

this[kDestroyed] = false
this[kOnDestroyed] = []
this[kOnDestroyed] = null
this[kClosed] = false
this[kOnClosed] = []
}
Expand Down Expand Up @@ -127,6 +127,7 @@ class DispatcherBase extends Dispatcher {
}

this[kDestroyed] = true
this[kOnDestroyed] = this[kOnDestroyed] || []
this[kOnDestroyed].push(callback)

const onDestroyed = () => {
Expand Down Expand Up @@ -167,7 +168,7 @@ class DispatcherBase extends Dispatcher {
throw new InvalidArgumentError('opts must be an object.')
}

if (this[kDestroyed]) {
if (this[kDestroyed] || this[kOnDestroyed]) {
throw new ClientDestroyedError()
}

Expand Down

0 comments on commit 7ef4270

Please sign in to comment.