Skip to content

Commit 3098232

Browse files
authored
fix: only close stream if it is open (#2823)
Adds a guard to the `.close` operation similar to the one on `.abort` that ensures we only close the stream if it is open. The individual `.closeRead`/`.closeWrite` operations already guard on the read/write status of the stream so there's no functional change, we just avoid a bit more async work as those methods return promises.
1 parent 4db0645 commit 3098232

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/integration-tests/test/circuit-relay.node.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ describe('circuit-relay', () => {
519519
await deferred.promise
520520

521521
// should have closed connections to remote and to relay
522-
expect(events[0].detail.remotePeer.toString()).to.equal(relay1.peerId.toString())
523-
expect(events[1].detail.remotePeer.toString()).to.equal(remote.peerId.toString())
522+
expect(events[0].detail.remotePeer.toString()).to.equal(remote.peerId.toString())
523+
expect(events[1].detail.remotePeer.toString()).to.equal(relay1.peerId.toString())
524524
})
525525

526526
it('should mark an outgoing relayed connection as limited', async () => {

packages/utils/src/abstract-stream.ts

+4
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ export abstract class AbstractStream implements Stream {
284284

285285
// Close for both Reading and Writing
286286
async close (options?: AbortOptions): Promise<void> {
287+
if (this.status !== 'open') {
288+
return
289+
}
290+
287291
this.log.trace('closing gracefully')
288292

289293
this.status = 'closing'

0 commit comments

Comments
 (0)