APPSRE-7875: Add request timeout handler #57
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the total time allotted for the lifespan of the request is controlled through the WriteTimeout property of the
http.Server
type, which is used to configure the server listener.However, this timeout is not only currently not working as intended (see the following list of issues), and there is also no way to propagate cancellation using Context properly - so that the SQL query can be cancelled on client disconnection or when the request timeout is reached.
The list of currently open WriteTimeout-related issues:
Server.WriteTimeout
is reached golang/go#59602Thus, add a middleware, called Timeout, that provides request timeout support and can be used to expire the execution of the subsequent handler in the chain. Also, make sure that the QueryContext() function is used to propagate the cancellation correctly.
The timeout can be controlled via an environment variable called
REQUEST_TIMEOUT
; the default is two minutes.While at it, upgrade the PostgreSQL driver and Red Hat's fork of OAuth2 Proxy to the latest stable releases.
Related: APPSRE-7875
Signed-off-by: Krzysztof Wilczyński [email protected]