From 67961ae762c71418fa31fc649040ebe783fa74cb Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Thu, 13 Nov 2025 17:23:26 +0530 Subject: [PATCH 1/4] Check if existing outbound stream is open or closed before aborting stream creation --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index fc89ff7a..56dedcea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -844,7 +844,7 @@ export class GossipSub extends TypedEventEmitter implements Pub // TODO make this behavior more robust // This behavior is different than for inbound streams // If an outbound stream already exists, don't create a new stream - if (this.streamsOutbound.has(id)) { + if (this.streamsOutbound.has(id)?.status === "open") { return } From 322e5ffdde0cabdf011afa9266727eb7fb11b533 Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Fri, 14 Nov 2025 08:57:47 +0530 Subject: [PATCH 2/4] Access status on rawStream `status` is actually a property of `OutboundStream.rawStream` --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 56dedcea..7d6f1b59 100644 --- a/src/index.ts +++ b/src/index.ts @@ -844,7 +844,7 @@ export class GossipSub extends TypedEventEmitter implements Pub // TODO make this behavior more robust // This behavior is different than for inbound streams // If an outbound stream already exists, don't create a new stream - if (this.streamsOutbound.has(id)?.status === "open") { + if (this.streamsOutbound.has(id)?.rawStream?.status === "open") { return } From c8716bad95f7ed2969e0bfa43b12dc7ed4d6979e Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Fri, 14 Nov 2025 08:58:42 +0530 Subject: [PATCH 3/4] Change to `get` `has` returns a boolean, not the stream. Use `get` instead. --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7d6f1b59..1bea9c37 100644 --- a/src/index.ts +++ b/src/index.ts @@ -844,7 +844,7 @@ export class GossipSub extends TypedEventEmitter implements Pub // TODO make this behavior more robust // This behavior is different than for inbound streams // If an outbound stream already exists, don't create a new stream - if (this.streamsOutbound.has(id)?.rawStream?.status === "open") { + if (this.streamsOutbound.get(id)?.rawStream?.status === "open") { return } From 888b89b4e325cb779ab99b34a8af55c807c25cfe Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Fri, 14 Nov 2025 09:00:17 +0530 Subject: [PATCH 4/4] Check stream status in `directConnect` Check not only if the stream exists but also if it is open in `directConnect`. --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 1bea9c37..4be272c2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1834,7 +1834,7 @@ export class GossipSub extends TypedEventEmitter implements Pub private async directConnect (): Promise { const toconnect: string[] = [] this.direct.forEach((id) => { - if (!this.streamsOutbound.has(id)) { + if (!this.streamsOutbound.get(id)?.rawStream?.status === "open") { toconnect.push(id) } })