diff --git a/config.go b/config.go index 5620a80..b6446bc 100644 --- a/config.go +++ b/config.go @@ -34,6 +34,9 @@ var DefaultConfig = Config{ Host: "127.0.0.1", Port: 34006, ShutdownTimeout: 10 * time.Second, + IdleTimeout: 60 * time.Second, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, }, Endpoint: endpointConfig{ BaseURL: "http://127.0.0.1:5000/", @@ -89,6 +92,9 @@ type listenConfig struct { Host string Port int ShutdownTimeout time.Duration + IdleTimeout time.Duration + ReadTimeout time.Duration + WriteTimeout time.Duration } func (c listenConfig) Addr() string { diff --git a/dalga.go b/dalga.go index 8120d36..6fecafe 100644 --- a/dalga.go +++ b/dalga.go @@ -61,7 +61,7 @@ func New(config Config) (*Dalga, error) { } s := scheduler.New(t, i.ID(), config.Endpoint.BaseURL, config.Endpoint.Timeout, r, config.Jobs.RandomizationFactor, config.Jobs.ScanFrequency, config.Jobs.MaxRunning) j := jobmanager.New(t, s) - srv := server.New(j, t, i.ID(), lis, config.Listen.ShutdownTimeout) + srv := server.New(j, t, i.ID(), lis, config.Listen.ShutdownTimeout, config.Listen.IdleTimeout, config.Listen.ReadTimeout, config.Listen.WriteTimeout) return &Dalga{ config: config, db: db, diff --git a/internal/server/server.go b/internal/server/server.go index de2c196..b0a794e 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -18,6 +18,9 @@ import ( type Server struct { shutdownTimeout time.Duration + idleTimeout time.Duration + readTimeout time.Duration + writeTimeout time.Duration jobs *jobmanager.JobManager table *table.Table instanceID uint32 @@ -26,9 +29,12 @@ type Server struct { done chan struct{} } -func New(j *jobmanager.JobManager, t *table.Table, instanceID uint32, l net.Listener, shutdownTimeout time.Duration) *Server { +func New(j *jobmanager.JobManager, t *table.Table, instanceID uint32, l net.Listener, shutdownTimeout, idleTimeout, readTimeout, writeTimeout time.Duration) *Server { s := &Server{ shutdownTimeout: shutdownTimeout, + idleTimeout: idleTimeout, + readTimeout: readTimeout, + writeTimeout: writeTimeout, jobs: j, table: t, instanceID: instanceID, @@ -74,9 +80,9 @@ func (s *Server) createServer() http.Server { m.Get("/status", http.HandlerFunc(s.handleStatus)) return http.Server{ Handler: m, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, - IdleTimeout: 10 * time.Second, + ReadTimeout: s.readTimeout, + WriteTimeout: s.writeTimeout, + IdleTimeout: s.idleTimeout, } }