Skip to content

Commit fb37c89

Browse files
committed
fix: catch top level exception when preemptively creating streams
1 parent 4a9360d commit fb37c89

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/core/src/lib/stream_manager.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { selectConnection } from "@waku/utils/libp2p";
66
import debug from "debug";
77

88
export class StreamManager {
9-
private streamPool: Map<string, Promise<Stream>>;
10-
private log: debug.Debugger;
9+
private streamPool: Map<string, Promise<Stream | void>>;
10+
private readonly log: debug.Debugger;
1111

1212
constructor(
1313
public multicodec: string,
@@ -38,7 +38,7 @@ export class StreamManager {
3838

3939
const stream = await streamPromise;
4040

41-
if (stream.status === "closed") {
41+
if (!stream || stream.status === "closed") {
4242
return this.newStream(peer); // fallback by creating a new stream on the spot
4343
}
4444

@@ -55,7 +55,10 @@ export class StreamManager {
5555
}
5656

5757
private prepareNewStream(peer: Peer): void {
58-
const streamPromise = this.newStream(peer);
58+
const streamPromise = this.newStream(peer).catch(() => {
59+
// No error thrown as this call is not triggered by the user
60+
this.log(`Failed to prepare a new stream for ${peer.id.toString()}`);
61+
});
5962
this.streamPool.set(peer.id.toString(), streamPromise);
6063
}
6164

0 commit comments

Comments
 (0)