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

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Apr 19, 2024

Backport of #52523 to release/8.0

/cc @BrennanConroy @damirault

Handle rejected promises inside incoming Invocation messages

Description

Using client results, which is a new feature in 7.0, the client sends a response back to the server after producing some sort of result. When sending the response back it's possible the connection closed, the SignalR library doesn't properly handle this and will result in an unhandled rejected promise.

Fixes #52524

Customer Impact

This can result in an unhandled rejected promise, which is an unwanted log in the browser and can crash the process if running in Node.js.

Regression?

  • Yes
  • No

Comes from a new feature introduced in 7.0 and has been there since.

Risk

  • High
  • Medium
  • Low

Small, easy to understand fix. Plus a nice test case to make sure it stays fixed.

Verification

  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

Incoming messages of Invocation type result in executing a clientMethod promise, but promise rejections are unhandled.
This can result in a unhandled rejected promise, potentially resulting in Node.js process crashing.
Note, this was previously detected via eslint and suppressed in code.

To avoid this, catch promise rejections and log the failure.

One scenario this case can happen is, if during the clientMethod call, the server connection is disconnected, the invokation will still attempt to send a completion message (through _sendWithProtocol). This will then result in a promise rejection, such as the following:

```
Cannot send data if the connection is not in the 'Connected' State.
    at HttpConnection.send (node_modules\@microsoft\signalr\dist\cjs\HttpConnection.js:95:35)
    at HubConnection._sendMessage (node_modules\@microsoft\signalr\dist\cjs\HubConnection.js:266:32)
    at HubConnection._sendWithProtocol (node_modules\@microsoft\signalr\dist\cjs\HubConnection.js:273:21)
    at HubConnection._invokeClientMethod (node_modules\@microsoft\signalr\dist\cjs\HubConnection.js:577:24)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
```
Adds a test covering when callback invoked when server invokes a method on the client and then handles rejected promise on send

When the unhandled promise fix is not applied to HubConnection,
 the following error fails the HubConnection.test.ts test suite:

    Send error

      831 |                         connection.send = () => {
      832 |                             promiseRejected = true;
    > 833 |                             return Promise.reject(new Error("Send error"));
          |                                                   ^
      834 |                         }
      835 |                         p.resolve();
      836 |                     });

      at TestConnection.connection.send (signalr/tests/HubConnection.test.ts:833:51)
      at HubConnection.send [as _sendMessage] (signalr/src/HubConnection.ts:422:32)
      at HubConnection._sendMessage [as _sendWithProtocol] (signalr/src/HubConnection.ts:433:25)
      at HubConnection._sendWithProtocol [as _invokeClientMethod] (signalr/src/HubConnection.ts:808:24)
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-signalr Includes: SignalR clients and servers label Apr 19, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 8.0.x milestone Apr 19, 2024
@BrennanConroy BrennanConroy added Servicing-consider Shiproom approval is required for the issue Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Apr 19, 2024
@RussKie
Copy link
Member

RussKie commented Apr 24, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label May 1, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label May 2, 2024
@wtgodbe
Copy link
Member

wtgodbe commented May 2, 2024

@BrennanConroy @halter73 good to go?

@BrennanConroy
Copy link
Member

Stephen and I approved the PR on main, I assume his approval won't change for release/8.0 😄 . So let's merge!

@wtgodbe wtgodbe merged commit 12adf59 into release/8.0 May 2, 2024
23 of 25 checks passed
@wtgodbe wtgodbe deleted the backport/pr-52523-to-release/8.0 branch May 2, 2024 16:43
@dotnet-policy-service dotnet-policy-service bot modified the milestones: 8.0.x, 8.0.6 May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants