Skip to content

Commit c1befb8

Browse files
committed
Fix link crash when pipelining a large amount of packets.
1 parent 6920f30 commit c1befb8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/cxxrtl/link.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class NodeStreamLink implements ILink {
7575
packetTexts.push(packetText);
7676
}
7777
});
78-
this.recvBuffer.splice(0, this.recvBuffer.length, rest[-1]);
78+
this.recvBuffer.splice(0, this.recvBuffer.length, rest.at(-1)!);
7979
}
8080

8181
// Second, process the packets. This involves steps that may throw errors, so we catch
@@ -87,11 +87,14 @@ export class NodeStreamLink implements ILink {
8787
const packet = JSON.parse(packetText) as wire.ServerPacket;
8888
try {
8989
await this.onRecv(packet);
90+
this.stream.resume();
9091
} catch (error) {
9192
console.error('uncaught error in onRecv', error);
93+
return; // leave paused
9294
}
9395
} catch (error) {
94-
console.error('malformed JSON', packetText);
96+
console.error('malformed JSON: ', packetText);
97+
return; // leave paused
9598
}
9699
}
97100
this.stream.resume();

0 commit comments

Comments
 (0)