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

[release/8.0] Handle rejected promises inside incoming Invocation messages #55230

Merged
merged 2 commits into from
May 2, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/SignalR/clients/ts/signalr/src/HubConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,10 @@ export class HubConnection {

switch (message.type) {
case MessageType.Invocation:
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this._invokeClientMethod(message);
this._invokeClientMethod(message)
.catch((e) => {
this._logger.log(LogLevel.Error, `Invoke client method threw error: ${getErrorString(e)}`)
});
break;
case MessageType.StreamItem:
case MessageType.Completion: {
Expand Down
32 changes: 32 additions & 0 deletions src/SignalR/clients/ts/signalr/tests/HubConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,38 @@ describe("HubConnection", () => {
});
});

it("callback invoked when server invokes a method on the client and then handles rejected promise on send", async () => {
await VerifyLogger.run(async (logger) => {
const connection = new TestConnection();
const hubConnection = createHubConnection(connection, logger);
let promiseRejected = false;
try {
await hubConnection.start();
const p = new PromiseSource<void>();
hubConnection.on("message", async () => {
// Force sending of response to error
connection.send = () => {
promiseRejected = true;
return Promise.reject(new Error("Send error"));
}
p.resolve();
});
connection.receive({
arguments: ["test"],
nonblocking: true,
target: "message",
invocationId: "0",
type: MessageType.Invocation,
});

await p;
expect(promiseRejected).toBe(true);
} finally {
await hubConnection.stop();
}
}, new RegExp("Invoke client method threw error: Error: Send error"));
});

it("stop on handshake error", async () => {
await VerifyLogger.run(async (logger) => {
const connection = new TestConnection(false);
Expand Down