Comments (7)
e.GET("/ping", func(c echo.Context) error {
c.Response().Flush()
return c.String(http.StatusOK, "pong")
})
Is not very good example. Or lets rephrase that - this shows that Timeout middleware has problems with handling requests that want to flush the response.
We could change Response.Flush()
to support unwrapping but I think we still should panic if unwrapping ends up with http.ErrNotSupported
. Hiding the fact that Flush
did not do anything hides potential problems. In that example we have explicit call for Flush which means that there is some requirement why we need to flush. No-oping that could be a bug.
Line 86 in 29aab27
to
func (r *Response) Flush() {
err := http.NewResponseController(r.Writer).Flush()
if err != nil && errors.Is(err, http.ErrNotSupported) {
panic(fmt.Errorf("response writer flushing is not supported"))
}
}
and make Timeout middleware support unwrapping (and other custom writers we have created)
from echo.
NB: you should avoid using Timeout middleware. In its basic form it just sends the response to the client and potentially does not end your handler goroutine if you have not properly implemented context cancellation checks.
If you want to properly handle timeout you need to implement context checks and this renders Timeout MW useless. As then you check for context.DeadlineExceeded
/context.Canceled
and know it is reached you will can send the response to client.
from echo.
I agree that it's supposed to cause panic if flushing is not supported, but at least, it should have a chance to unwrap parent writers to check if there is a flusher one.
from echo.
About timeout middleware, I don't fully understand you, It does just what I want it to do - cancel context, if timeout is reached
from echo.
I'll create PR for #2592 (comment) changes
@qerdcv in you example you are using middleware.TimeoutWithConfig
this uses goroutine to serve your request. Maybe you wanted to use middleware.ContextTimeout()
?
- ContextTimeout just replaces context for request
echo/middleware/context_timeout.go
Line 61 in ea529bb
- TimeoutWithConfig runs your request in separate goroutine
Line 124 in ea529bb
https://github.com/golang/go/blob/e17e5308fd5a26da5702d16cc837ee77cdb30ab6/src/net/http/server.go#L3590-L3598
There are recommendations for timeout handling at the start of https://github.com/labstack/echo/blob/ea529bbab6602db8bd9fc0746405a3687ffbd885/middleware/timeout.go
from echo.
It seems that you are right.
I'll recheck what behaviour exactly I need.
Thanks!
from echo.
Related Issues (20)
- Not able to detect the route url without \ HOT 9
- CSRF TokenLookup HOT 1
- Add an AllowContentType middleware (based on chi)
- Bind() panics when the destination is a map with non-interface types HOT 1
- Add SSE function in Context.Response HOT 7
- Any software design issues HOT 1
- Request support for more routing path matching HOT 1
- Unable to use proxy middleware along with bodyDump middleware HOT 1
- `Host` header always blank HOT 6
- Does echo support i18n? [feature request] HOT 2
- Weirdness with wrapped handler and embed FS (static files) HOT 1
- Remove default charset from 'application/json' Content-Type header
- echo v4 websocket client closed, program exited HOT 3
- router not setting ContextKeyHeaderAllow for group, causing cors preflight to not work HOT 6
- Static file has wrong body returned when using a custom HTTP Error Handler and complex paths HOT 2
- QueryParams seem to override formValues HOT 3
- DefaultHTTPErrorHandler does not log HOT 3
- Support Casbin Authorization Middleware HOT 1
- Feature request: support Yaml responses transparently. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from echo.