--- title: "ADR 0060: Listener handler timeout and graceful shutdown" --- * Status: accepted * Code: [`pkg/adapter/adapter.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/adapter/adapter.go) ## Context The controller listener serves webhook and `/incoming` requests. For incoming webhooks and for GitHub Apps with many installations the handler is slow: a comment in the code measured about 180s for an app with roughly 400 installations. On OpenShift the route in front of the controller has its own timeout, 30s by default. ## Decision * `httpTimeoutHandler` is 600 seconds and wraps the mux in `http.TimeoutHandler`, answering `Listener Timeout!` when exceeded. The code does not show how 600 was chosen beyond being well above the measured 180s. * `ReadHeaderTimeout`, `ReadTimeout` and `IdleTimeout` are set to 5s, 10s and 30s on the server; the handler timeout is the only long one. * When the context is cancelled (the knative signal handling delivers SIGTERM/SIGINT through it), the listener calls `srv.Shutdown` with a 10 second deadline so in-flight requests can finish and the process exits before the pod grace period ends. The tracer provider is shut down separately with a 5 second deadline. * `ListenAndServe*` runs in a goroutine and reports through a channel; `http.ErrServerClosed` is treated as a clean exit. ## Consequences * A deployment fronted by an OpenShift route must raise the route timeout to match, otherwise the route cuts the request at 30s while the controller keeps working. * A request still running after the 10 second shutdown deadline is dropped by `Shutdown` returning its deadline error. * Changing the handler timeout does not change the read and idle timeouts; they are independent constants in the same literal.