Skip to content

Commit

Permalink
Bugfix: fix infinite loop in packet if packet end not in minLength (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesper Lindstrøm Nielsen authored Nov 8, 2021
1 parent 7bd3427 commit fade77b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,16 @@ export class Reader {
if (this.listenRef <= 0) {
throw NotListeningError;
}
const deadline = Date.now() + timeoutMs;
while (true) {
await this.waitData(minLength, timeoutMs);
await this.waitData(minLength, deadline - Date.now());

const res = this.buffer.packet();
if (res !== undefined) {
return res;
}
// no packet was available in minLength, so we wait for another byte.
minLength++;
}
}
}
Expand Down

0 comments on commit fade77b

Please sign in to comment.