kit icon indicating copy to clipboard operation
kit copied to clipboard

Add Error Handling for Canceled Contexts during request lifecycle

Open gabizou opened this issue 1 year ago • 3 comments

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
	}

gabizou avatar Oct 10 '23 15:10 gabizou

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.

peterbourgon avatar Oct 10 '23 20:10 peterbourgon

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?

gabizou avatar Oct 12 '23 16:10 gabizou

@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!

omrihq avatar May 10 '24 21:05 omrihq