-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support/db: Allow passing context.Context with deadline to Session methods #1950
Comments
Adding as a stretch goal to Horizon 0.24.0. |
When using the It's also worth highlighting that the timeout requires that second connection to postgres to manually cancel the query. Example using context timeout: &pq.Error{Severity:"ERROR", Code:"57014", Message:"canceling statement due to user request", Detail:"", Hint:"", Position:"", InternalPosition:"", InternalQuery:"", Where:"", Schema:"", Table:"", Column:"", DataTypeName:"", Constraint:"", File:"postgres.c", Line:"3124", Routine:"ProcessInterrupts"} Example using statement timeout: &pq.Error{Severity:"ERROR", Code:"57014", Message:"canceling statement due to statement timeout", Detail:"", Hint:"", Position:"", InternalPosition:"", InternalQuery:"", Where:"", Schema:"", Table:"", Column:"", DataTypeName:"", Constraint:"", File:"postgres.c", Line:"3094", Routine:"ProcessInterrupts"} However, using a context does give us the ability to control the timeout independently for each query. If we need that then using the context seems like the right way to go but we should be aware of the tradeoff above. We could also investigate setting the I think we should evaluate all three approaches:
|
What I was trying to say is that when a developer passes The other advantage is that all future apps that use
It's also possible that this depends on the config value. Ex. Horizon admin can define timeout period for requests (ex. to make sure the user receives the response before LB idle timeout): |
Realized that |
Closed in #1977. |
What problem does your feature solve?
It should be possible to pass
context.Context
to set timeout for queries sent to a database. This is to prevent long running queries to occupy DB connection for a long period of time.What would you like to see?
The easiest way to solve this is to use
sqlx.*Context
methods that allow passingcontext.Context
and updatedb.Session
methods to acceptcontext.Context
param.What alternatives are there?
Users can set
statement_timeout
in Postgres however it requires changing DB config and also return an error that is unexpected for an application.The text was updated successfully, but these errors were encountered: