From 53ee2281bcc7e465aa59864075f6cf60f0495dd8 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Sun, 3 May 2026 11:19:20 -0600 Subject: [PATCH] timeout values now in config --- config/config.go | 11 ++++++++--- config/default.yaml | 4 ++++ main.go | 13 ++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/config/config.go b/config/config.go index 7bff179..ef34243 100644 --- a/config/config.go +++ b/config/config.go @@ -167,7 +167,12 @@ type AmConfig struct { } `yaml:"posting"` Tuning struct { WorkerTasks int `yaml:"workerTasks"` - Queues struct { + Timeouts struct { + HttpRead int `yaml:"httpRead"` + HttpWrite int `yaml:"httpWrite"` + HttpIdle int `yaml:"httpIdle"` + } `yaml:"timeouts"` + Queues struct { AuditWrites int `yaml:"auditWrites"` ContextRecycle int `yaml:"contextRecycle"` EmailRecycle int `yaml:"emailRecycle"` @@ -200,7 +205,7 @@ func (c *AmConfig) ExPath(path string) string { return filepath.Join(c.baseDir, path) } -// AmConfigComputed is the configuration values which are "computed" based only on values in AmConfig. +// AmConfigComputed is the configuration values which are "computed" based only on values in AmConfig and CommandLine. type AmConfigComputed struct { DebugMode bool // are we in debug mode? LogLevel string // the logging level @@ -321,7 +326,7 @@ func overlayStructValue(dest, loaded, defaults reflect.Value) { } } else { // if we see this message, this function needs more work - log.Errorf("*** unable to deal with field %s of type %s", structField.Name, typ.Name()) + log.Fatalf("*** unable to deal with field %s of type %s", structField.Name, typ.Name()) } } } diff --git a/config/default.yaml b/config/default.yaml index a12e5e6..416b535 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -91,6 +91,10 @@ posting: - "image/png" tuning: workerTasks: 4 + timeouts: + httpRead: 30 + httpWrite: 30 + httpIdle: 120 queues: auditWrites: 16 contextRecycle: 16 diff --git a/main.go b/main.go index 031b0aa..464735c 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,9 @@ import ( log "github.com/sirupsen/logrus" ) +// READ_HEADER_TIMEOUT is the timeout value for reading headers in seconds. (Deliberately NOT configurable because this is a security issue) +const READ_HEADER_TIMEOUT = 2 + // GetAndPost is used to have functions that respond to both GET and POST on a URI. var GetAndPost = []string{http.MethodGet, http.MethodPost} @@ -214,7 +217,7 @@ func setupEcho() *echo.Echo { // ampool is the worker pool for one-shot background tasks. var ampool *util.WorkerPool -// SystemStartTime records the time since the system was started. +// SystemStartTime records the time the system was started. var SystemStartTime time.Time // main is Ye Olde Main Function. @@ -273,10 +276,10 @@ func main() { log.Fatalf("error in shutting down the server: %v", err) }, BeforeServeFunc: func(s *http.Server) error { - s.ReadTimeout = 30 * time.Second - s.WriteTimeout = 30 * time.Second - s.IdleTimeout = 120 * time.Second - s.ReadHeaderTimeout = 2 * time.Second + s.ReadTimeout = time.Duration(config.GlobalConfig.Tuning.Timeouts.HttpRead) * time.Second + s.WriteTimeout = time.Duration(config.GlobalConfig.Tuning.Timeouts.HttpWrite) * time.Second + s.IdleTimeout = time.Duration(config.GlobalConfig.Tuning.Timeouts.HttpIdle) * time.Second + s.ReadHeaderTimeout = READ_HEADER_TIMEOUT * time.Second return nil }, }