Skip to content

Commit

Permalink
Merge branch 'fix/pipe-uncaught-error' into 'dev'
Browse files Browse the repository at this point in the history
fix(rosenet-node): fix issue in protocol handler pipe

Closes #77

See merge request ergo/rosen-bridge/rosenet!37
  • Loading branch information
vorujack committed Sep 16, 2024
2 parents 7686c5f + 95ead7a commit 8ceb3a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-hats-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/rosenet-node': patch
---

Fix issue of RoseNet direction protocol listener pipe not getting awaited
43 changes: 26 additions & 17 deletions packages/rosenet-node/lib/rosenet-direct/handleIncomingMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,32 @@ const handleIncomingMessageFactory =
transient: connection.transient,
},
);
pipe(
stream,
decode,
async function* (source) {
for await (const message of source) {
RoseNetNodeContext.logger.debug(
'message received, calling handler and sending ack',
{
message,
},
);
handler(connection.remotePeer.toString(), message);
yield Uint8Array.of(ACK_BYTE);
}
},
stream,
);
try {
await pipe(
stream,
decode,
async function* (source) {
for await (const message of source) {
RoseNetNodeContext.logger.debug(
'message received, calling handler and sending ack',
{
message,
},
);
handler(connection.remotePeer.toString(), message);
yield Uint8Array.of(ACK_BYTE);
}
},
stream,
);
} catch (error) {
RoseNetNodeContext.logger.warn(
'An error occurred while reading from stream',
{
error,
},
);
}
},
{ runOnTransientConnection: true },
);
Expand Down

0 comments on commit 8ceb3a6

Please sign in to comment.