From 72d4a043db48bb8196fbf60b99f9d59ef827bf8b Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 22 Mar 2025 14:20:07 +0800 Subject: [PATCH] Configurable timeout --- config.go | 3 +++ forge.scfg | 4 ++++ main.go | 6 +++--- diff --git a/config.go b/config.go index 5382bbed67ac077b1bbf7d3a8cf009541642a38d..3721fd60c5ad5d10c7f2d1a1a57632eb3d2c7954 100644 --- a/config.go +++ b/config.go @@ -21,6 +21,9 @@ Net string `scfg:"net"` Addr string `scfg:"addr"` CookieExpiry int `scfg:"cookie_expiry"` Root string `scfg:"root"` + ReadTimeout uint `scfg:"read_timeout"` + WriteTimeout uint `scfg:"write_timeout"` + IdleTimeout uint `scfg:"idle_timeout"` } `scfg:"http"` Hooks struct { Socket string `scfg:"socket"` diff --git a/forge.scfg b/forge.scfg index 42a4b57264e44499c55e378946db7eacc40098f0..e2b703ec382406b409bf20d30f2e163c860381d7 100644 --- a/forge.scfg +++ b/forge.scfg @@ -13,6 +13,10 @@ cookie_expiry 604800 # What is the canonical URL of the web root? root https://forge.example.org + + read_timeout 120 + write_timeout 120 + idle_timeout 120 } irc { diff --git a/main.go b/main.go index 1530d9097eb33b821b818dea45c143690a481c06..444e5b0da1e36bff4cb67fbb9f55055b255d2033 100644 --- a/main.go +++ b/main.go @@ -89,9 +89,9 @@ clog.Fatal(1, "Listening HTTP: "+err.Error()) } server := http.Server{ Handler: &forgeHTTPRouter{}, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, - IdleTimeout: 60 * time.Second, + ReadTimeout: time.Duration(config.HTTP.ReadTimeout) * time.Second, + WriteTimeout: time.Duration(config.HTTP.ReadTimeout) * time.Second, + IdleTimeout: time.Duration(config.HTTP.ReadTimeout) * time.Second, } //exhaustruct:ignore clog.Info("Listening HTTP on " + config.HTTP.Net + " " + config.HTTP.Addr) go func() { -- 2.48.1