Quadruple all HTTP timeouts to prevent timeout errors
- HTTP request timeout: 2s -> 8s - Stats collection context timeout: 1s -> 4s - HTTP read header timeout: 10s -> 40s This should prevent timeout errors when the database is under load or when complex queries take longer than expected (slow query threshold is 50ms).
This commit is contained in:
parent
3338e92785
commit
1fded42651
@ -80,8 +80,8 @@ func (s *Server) handleStatusJSON() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Create a 1 second timeout context for this request
|
// Create a 4 second timeout context for this request
|
||||||
ctx, cancel := context.WithTimeout(r.Context(), 1*time.Second)
|
ctx, cancel := context.WithTimeout(r.Context(), 4*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
metrics := s.streamer.GetMetrics()
|
metrics := s.streamer.GetMetrics()
|
||||||
@ -214,8 +214,8 @@ func (s *Server) handleStats() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Create a 1 second timeout context for this request
|
// Create a 4 second timeout context for this request
|
||||||
ctx, cancel := context.WithTimeout(r.Context(), 1*time.Second)
|
ctx, cancel := context.WithTimeout(r.Context(), 4*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Check if context is already cancelled
|
// Check if context is already cancelled
|
||||||
|
@ -16,7 +16,7 @@ func (s *Server) setupRoutes() {
|
|||||||
r.Use(middleware.RealIP)
|
r.Use(middleware.RealIP)
|
||||||
r.Use(middleware.Logger)
|
r.Use(middleware.Logger)
|
||||||
r.Use(middleware.Recoverer)
|
r.Use(middleware.Recoverer)
|
||||||
const requestTimeout = 2 * time.Second
|
const requestTimeout = 8 * time.Second
|
||||||
r.Use(TimeoutMiddleware(requestTimeout))
|
r.Use(TimeoutMiddleware(requestTimeout))
|
||||||
r.Use(JSONResponseMiddleware)
|
r.Use(JSONResponseMiddleware)
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func (s *Server) Start() error {
|
|||||||
port = "8080"
|
port = "8080"
|
||||||
}
|
}
|
||||||
|
|
||||||
const readHeaderTimeout = 10 * time.Second
|
const readHeaderTimeout = 40 * time.Second
|
||||||
s.srv = &http.Server{
|
s.srv = &http.Server{
|
||||||
Addr: ":" + port,
|
Addr: ":" + port,
|
||||||
Handler: s.router,
|
Handler: s.router,
|
||||||
|
Loading…
Reference in New Issue
Block a user