Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX partial frames during connect's peek of the info block #201

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nats-base-client/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export function protoLen(ba: Uint8Array): number {
return n + 1;
}
}
return -1;
return 0;
}

export function extractProtocolMessage(a: Uint8Array): string {
// protocol messages are ascii, so Uint8Array
const len = protoLen(a);
if (len) {
if (len > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you changed from -1 to 0, the test if (len) { would then become valid, but I am ok being explicit here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap going to keep it that way - at some point I believe the code returned 0, and then changed (this was used by the protocol parser before. Testing for what we are looking for is always a good thing.

const ba = new Uint8Array(a);
const out = ba.slice(0, len);
return TD.decode(out);
Expand Down
2 changes: 1 addition & 1 deletion src/deno_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class DenoTransport implements Transport {
inbound.fill(frame);
const raw = inbound.peek();
pm = extractProtocolMessage(raw);
if (pm) {
if (pm !== "") {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/protocol_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ Deno.test("protocol - cancel unknown sub", () => {
});

Deno.test("protocol - protolen -1 on empty", () => {
assertEquals(protoLen(Empty), -1);
assertEquals(protoLen(Empty), 0);
assertEquals(extractProtocolMessage(Empty), "");
});