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

ContextWithTimeout middleware feature request #2379

Closed
hakankutluay opened this issue Jan 19, 2023 · 1 comment · Fixed by #2380
Closed

ContextWithTimeout middleware feature request #2379

hakankutluay opened this issue Jan 19, 2023 · 1 comment · Fixed by #2380

Comments

@hakankutluay
Copy link
Contributor

Issue Description

Need timeout support on long-running operations like Db, HTTP calls, etc. timeout middleware supports cancellation with context but has race conditions.

We need a middleware that creates context with timeout and injects ContextWithTimeout to c.Request().Context()
New approach also fixes #2306.

Expected behaviour

We need to introduce a new middleware (middleware.ContextTimeout()) that creates context with timeout and injects ContextWithTimeout to c.Request().Context(). If the handler returns an error that wraps context.DeadlineExceeded, it returns Service Unavailable (503)

New approach also fixes #2306.

Actual behaviour

With current timeout middleware, since it has a race condition, it is not safe to use in production.

@vigo
Copy link

vigo commented Jan 20, 2023

great work @hakankutluay ! thanx buddy!

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 a pull request may close this issue.

2 participants