Skip to content

Commit 129d703

Browse files
author
John Wregglesworth
committed
Add configurable timeouts to the server
1 parent 6ea4b5c commit 129d703

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

main.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ func main() {
678678
checkResourceAccessBase = flag.String("check-resource-access-base", "http://check-resource-access", "The base URL for the check-resource-access service.")
679679
externalID = flag.String("external-id", "", "The external ID to pass to the apps service when looking up the analysis ID.")
680680
encodedSSOTimeout = flag.String("sso-timeout", "5s", "The timeout period for back-channel requests to the identity provider.")
681+
encodedReadTimeout = flag.String("read-timeout", "48h", "The maximum duration for reading the entire request, including the body.")
682+
encodedWriteTimeout = flag.String("write-timeout", "48h", "The maximum duration before timing out writes of the response.")
683+
encodedIdleTimeout = flag.String("idle-timeout", "5000s", "The maximum amount of time to wait for the next request when keep-alives are enabled.")
681684
)
682685

683686
flag.Var(&corsOrigins, "allowed-origins", "List of allowed origins, separated by commas.")
@@ -715,6 +718,9 @@ func main() {
715718
log.Infof("Keycloak realm is %s", *keycloakRealm)
716719
log.Infof("Keycloak client ID is %s", *keycloakClientID)
717720
log.Infof("Keycloak client secret is %s", *keycloakClientSecret)
721+
log.Infof("read timeout is %s", *encodedReadTimeout)
722+
log.Infof("write timeout is %s", *encodedWriteTimeout)
723+
log.Infof("idle timeout is %s", *encodedIdleTimeout)
718724

719725
for _, c := range corsOrigins {
720726
log.Infof("Origin: %s\n", c)
@@ -739,6 +745,22 @@ func main() {
739745
log.Fatalf("invalid timeout duration for back-channel requests to the IdP: %s", err.Error())
740746
}
741747

748+
// Decode the timeout durations for the HTTP server.
749+
readTimeout, err := time.ParseDuration(*encodedReadTimeout)
750+
if err != nil {
751+
log.Fatalf("invalid read timeout duration: %s", err.Error())
752+
}
753+
754+
writeTimeout, err := time.ParseDuration(*encodedWriteTimeout)
755+
if err != nil {
756+
log.Fatalf("invalid write timeout duration: %s", err.Error())
757+
}
758+
759+
idleTimeout, err := time.ParseDuration(*encodedIdleTimeout)
760+
if err != nil {
761+
log.Fatalf("invalid idle timeout duration: %s", err.Error())
762+
}
763+
742764
// Create an HTTP client to use for back-channel requests to the identity provider.
743765
client := &http.Client{
744766
Timeout: ssoTimeout,
@@ -784,8 +806,11 @@ func main() {
784806
})
785807

786808
server := &http.Server{
787-
Handler: c.Handler(r),
788-
Addr: *listenAddr,
809+
Handler: c.Handler(r),
810+
Addr: *listenAddr,
811+
ReadTimeout: readTimeout,
812+
WriteTimeout: writeTimeout,
813+
IdleTimeout: idleTimeout,
789814
}
790815
if useSSL {
791816
err = server.ListenAndServeTLS(*sslCert, *sslKey)

0 commit comments

Comments
 (0)