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

Add Error Handling for Canceled Contexts during request lifecycle #1277

Open
gabizou opened this issue Oct 10, 2023 · 3 comments
Open

Add Error Handling for Canceled Contexts during request lifecycle #1277

gabizou opened this issue Oct 10, 2023 · 3 comments

Comments

@gabizou
Copy link

gabizou commented Oct 10, 2023

What would you like?

Various lifecycle steps can cancel a context.Context, but it would be the responsibility of each consumer to verify the context isn't canceled. It would be great to add:

	for _, f := range s.before {
		ctx = f(ctx, r)
		if ctx.Err() == context.Canceled {
			err := context.Cause(ctx)
			s.errorHandler.Handle(ctx, err)
			s.errorEncoder(ctx, err, w)
			return
		}
	}
	

	request, err := s.dec(ctx, r)
	if err != nil {
		s.errorHandler.Handle(ctx, err)
		s.errorEncoder(ctx, err, w)
		return
	}
@peterbourgon
Copy link
Member

it would be the responsibility of each consumer to verify the context isn't canceled

This is already the case -- consumers must always inspect the received context, and return if it is finished.

@gabizou
Copy link
Author

gabizou commented Oct 12, 2023

That's fair, but would it make sense to treat the Server as a consumer of the context and "bail" if the context is finished early?

@omrihq
Copy link

omrihq commented May 10, 2024

@peterbourgon I'm curious if there's been any updates here? I'm running into this issue myself and wondering if we could bake cancellation if ctx.Err() == context.Canceled into the request lifecycle.

Thank you!

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

No branches or pull requests

3 participants