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

Update HandlerContext signal to trigger on other reasons than timeouts #531

Merged
merged 8 commits into from May 10, 2023
Merged

Update HandlerContext signal to trigger on other reasons than timeouts #531

merged 8 commits into from May 10, 2023

Conversation

ghost
Copy link

@ghost ghost commented Mar 14, 2023

This PR renames the AbortSignal property in the HandlerContext from deadline to a more generic signal.

It also adds a signal to universal server requests and links it to the handler context signal.

We expect server plugins to trigger the AbortSignal of the request when a request is finished or aborted prematurely.

As a result, service implementations can now rely on the signal of the HandlerContext to clean up, whether the RPC timed out (via a deadline), whether the client canceled the request, or whether the request finished normally.

@timostamm
Copy link
Member

Thank you for the PR, Johyn! We'll take a look soon.

@CLAassistant
Copy link

CLAassistant commented Apr 29, 2023

CLA assistant check
All committers have signed the CLA.

@ghost
Copy link
Author

ghost commented May 2, 2023

After reading #591, I wonder if we could just abort the deadline signal when the request is closed instead of adding another signal.

Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

Hey @johynpapin, took me a minute to get back to this 😊

Adding the signal to the UniversalServerRequest, aborting it in node-universal-handler.ts, and making it available in the HandlerContext is a good call.

There is one small but important bit though: HTTP/2 has a set of error codes (spec), and gRPC defines a mapping between these codes, and gRPC error codes (spec). If a HTTP/2 client cancels a request, it should close the stream with the HTTP/2 code CANCEL (implemented in #552). The server should pick this code up, and convert it to a Connect/gRPC code "canceled".

If you can spare the time to update the PR, we'd be super happy to have it 🙂

packages/connect-node/src/node-universal-handler.ts Outdated Show resolved Hide resolved
packages/connect/src/implementation.ts Show resolved Hide resolved
@ghost
Copy link
Author

ghost commented May 9, 2023

Hey @timostamm! 👋

Thank you very much for this detailed answer. I suspected that there was a problem with the error handling, it's clearer to me now.

I will take the time to understand and make these changes! 😄

Johyn Papin added 3 commits May 9, 2023 16:33
Signed-off-by: Johyn Papin <contact@johyn.me>
Signed-off-by: Johyn Papin <contact@johyn.me>
Signed-off-by: Johyn Papin <contact@johyn.me>
Signed-off-by: Johyn Papin <contact@johyn.me>
Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

Looks great!

Do not worry about the CI failure. The fork does not have access to the secret that is required for browserstack. As long as make passes (as it did), everything is fine, since we are not touching code that directly affects @bufbuild/connect-web.

I'm going to think about test coverage tomorrow morning and get back to you.

packages/connect/src/implementation.ts Outdated Show resolved Hide resolved
packages/connect/src/implementation.ts Outdated Show resolved Hide resolved
Johyn Papin and others added 4 commits May 9, 2023 20:10
@timostamm
Copy link
Member

I pushed up basic tests in cdd0e81. They simply assert that the signal from the request triggers the signal in the HandlerContext. We do not verify that an error raised from this signal is correctly written to the response. We will follow up with test coverage in the test suite that runs a Node.js server.

Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

Thank for for the contribution, Johyn, LGTM!

I'm going to update the PR description, and also update the description of #591 for the renamed HandlerContext property.

Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

Thank for for the contribution, Johyn, LGTM!

I'm going to update the PR description, and also update the description of #591 for the renamed HandlerContext property.

@timostamm timostamm changed the title Add an AbortSignal to HandlerContext Update HandlerContext signal May 10, 2023
@timostamm timostamm merged commit 8e20273 into connectrpc:main May 10, 2023
4 of 5 checks passed
@timostamm timostamm changed the title Update HandlerContext signal Update HandlerContext signal to trigger on other reasons than timeouts May 17, 2023
@timostamm timostamm mentioned this pull request May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants