Skip to content
Open
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
18 changes: 10 additions & 8 deletions packages/memcache-client/src/lib/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,16 @@ export class MemcacheConnection extends MemcacheParser {
receiveResult(pending: ParserPendingData): void {
if (this.isReady()) {
const retrieve = this.peekCommand();
try {
retrieve.results[pending.cmdTokens[1]] = {
tokens: pending.cmdTokens,
casUniq: pending.cmdTokens[4],
value: this.client?._unpackValue(pending as unknown as PackedData),
};
} catch (err) {
retrieve.error = err as Error;
if (retrieve) {
try {
retrieve.results[pending.cmdTokens[1]] = {
tokens: pending.cmdTokens,
casUniq: pending.cmdTokens[4],
value: this.client?._unpackValue(pending as unknown as PackedData),
};
} catch (err) {
retrieve.error = err as Error;
}
}
}
delete pending.data;
Expand Down
12 changes: 12 additions & 0 deletions packages/memcache-client/src/test/spec/connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,16 @@ describe.only("MemcacheConnection", function () {
);
x._shutdown("test");
});

it("receiveResult should not crash when peekCommand returns undefined", () => {
const x = new MemcacheConnection({ socketID: 1 } as unknown as MemcacheClient);
x._status = Status.READY;
x.peekCommand = () => undefined as any;
expect(() => {
x.receiveResult({
cmdTokens: ["VALUE", "testkey", "0", "5"],
key: "testkey",
});
}).not.toThrow();
});
});