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

Timeout middleware implementation #1743

Merged
merged 1 commit into from
Jan 5, 2021

Conversation

ilijamt
Copy link
Contributor

@ilijamt ilijamt commented Dec 30, 2020

There are occasions when you want to add a timeout to your handlers, so they get finished within a specified period of time.

@codecov
Copy link

codecov bot commented Dec 30, 2020

Codecov Report

Merging #1743 (4e2e46b) into master (f718079) will increase coverage by 0.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1743      +/-   ##
==========================================
+ Coverage   86.75%   86.88%   +0.13%     
==========================================
  Files          29       30       +1     
  Lines        2069     2090      +21     
==========================================
+ Hits         1795     1816      +21     
  Misses        175      175              
  Partials       99       99              
Impacted Files Coverage Δ
middleware/timeout.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f718079...4e2e46b. Read the comment docs.

@ilijamt
Copy link
Contributor Author

ilijamt commented Dec 30, 2020

Currently Go 1.12 is skipped due to missing Request.Clone, is this something that should really be added or can we live without it?

I was considering adding a separate file for go 1.12 using Request.WithContext but that only creates a shallow clone, and I don't know what are the implications of it with other usecases.

@lammel lammel linked an issue Jan 1, 2021 that may be closed by this pull request
3 tasks
@lammel
Copy link
Contributor

lammel commented Jan 2, 2021

We just need to clarify if a timeout middleware should be part of echo core. As we are also preparing a rate limiter in #1724 I guess this may fit into core too.

middleware/timeout.go Outdated Show resolved Hide resolved
middleware/timeout.go Show resolved Hide resolved
middleware/timeout_test.go Outdated Show resolved Hide resolved
middleware/timeout_test.go Outdated Show resolved Hide resolved
middleware/timeout_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@pafuent pafuent left a comment

Choose a reason for hiding this comment

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

LGTM!
Please improve the TestTimeoutTestRequestClone test and I'll approve the PR


m := TimeoutWithConfig(TimeoutConfig{
Timeout: time.Second,
ErrorHandler: func(err error, c echo.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of checking if the Context was cloned properly on the ErrorHandler function, do it directly on the HandlerFunc that you pass to the Timeout middleware. It'll be more straightforward and probably the test will run faster because is not needed to wait for the timeout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to the handler

Copy link
Contributor

@pafuent pafuent left a comment

Choose a reason for hiding this comment

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

LGTM!
Thanks for the new Middleware!!!
In your futures PRs, please add new commits instead of updating the original one, that helps a lot during review (I can focus on the new changes and ignore the already reviewed code)

@lammel
Copy link
Contributor

lammel commented Jan 5, 2021

Great!

So what is missing now is documentation.
@ilijamt Could you do a PR in labstack/echox to add docs for our shine new timeout middleware?

@lammel lammel merged commit 67263b5 into labstack:master Jan 5, 2021
@ilijamt
Copy link
Contributor Author

ilijamt commented Jan 5, 2021 via email

@ilijamt
Copy link
Contributor Author

ilijamt commented Jan 7, 2021

I added a MR labstack/echox#173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timeout middleware
3 participants