Skip to content

Commit

Permalink
fix: catch top level exception when preemptively creating streams
Browse files Browse the repository at this point in the history
  • Loading branch information
fryorcraken committed Sep 20, 2023
1 parent 756ca81 commit e0d6eb6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/core/src/lib/stream_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { selectConnection } from "@waku/utils/libp2p";
import debug from "debug";

export class StreamManager {
private streamPool: Map<string, Promise<Stream>>;
private log: debug.Debugger;
private streamPool: Map<string, Promise<Stream | void>>;
private readonly log: debug.Debugger;

constructor(
public multicodec: string,
Expand Down Expand Up @@ -38,7 +38,7 @@ export class StreamManager {

const stream = await streamPromise;

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

Expand All @@ -55,7 +55,10 @@ export class StreamManager {
}

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

Expand Down

0 comments on commit e0d6eb6

Please sign in to comment.