summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/echo/v4/middleware/timeout.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/middleware/timeout.go')
-rw-r--r--vendor/github.com/labstack/echo/v4/middleware/timeout.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/vendor/github.com/labstack/echo/v4/middleware/timeout.go b/vendor/github.com/labstack/echo/v4/middleware/timeout.go
index 68f464e4..5d23ff45 100644
--- a/vendor/github.com/labstack/echo/v4/middleware/timeout.go
+++ b/vendor/github.com/labstack/echo/v4/middleware/timeout.go
@@ -42,8 +42,8 @@ var (
}
)
-// Timeout returns a middleware which recovers from panics anywhere in the chain
-// and handles the control to the centralized HTTPErrorHandler.
+// Timeout returns a middleware which returns error (503 Service Unavailable error) to client immediately when handler
+// call runs for longer than its time limit. NB: timeout does not stop handler execution.
func Timeout() echo.MiddlewareFunc {
return TimeoutWithConfig(DefaultTimeoutConfig)
}
@@ -106,6 +106,11 @@ func (t echoHandlerFuncWrapper) ServeHTTP(rw http.ResponseWriter, r *http.Reques
// so on timeout writer stays what http.TimeoutHandler uses and prevents writing headers/body
t.ctx.Response().Writer = originalWriter
if err != nil {
+ // call global error handler to write error to the client. This is needed or `http.TimeoutHandler` will send status code by itself
+ // and after that our tries to write status code will not work anymore
+ t.ctx.Error(err)
+ // we pass error from handler to middlewares up in handler chain to act on it if needed. But this means that
+ // global error handler is probably be called twice as `t.ctx.Error` already does that.
t.errChan <- err
}
}