Skip to content

Added timeout to Postgres queries#9

Merged
camposeddie merged 2 commits intomasterfrom
cbc0024-7458-query-timeout
Sep 9, 2025
Merged

Added timeout to Postgres queries#9
camposeddie merged 2 commits intomasterfrom
cbc0024-7458-query-timeout

Conversation

@ccollinsuah
Copy link
Copy Markdown
Contributor

Queries executed by the lambda now have a timeout less than the lambda's max run time, configured by the connection's statement_timeout. Currently, the lambda has at 1 second grace period to cover other operations such as closing the Postgres connection in the event of a query timeout. It may be worth making this grace period either configurable via Terraform or proportional to the lambda's max run time. This flat grace period might not be adequate for S3 writes in cases where a hypothetical long running query returns just shy of the statement_timeout. Let me know if you think either of these additions are appropriate.

Psycopg connections were also not being closed and that has been fixed. Psycopg2 connections use contexts as separate transactions instead of closing at the end of them, so until now the lambda was not gracefully closing its connections.

Copy link
Copy Markdown
Contributor

@camposeddie camposeddie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think everything looks good as a first pass on getting functionality built into the lambda. For the future, it may be better to separate the query timeout from lambda timeout to allow more granular control over each. For our current use case, this works fine 👍

@camposeddie camposeddie merged commit c6f4440 into master Sep 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants