Jira (PDB-4937) Add a default statement timeout to user queries

2 views
Skip to first unread message

Austin Blatt (Jira)

unread,
Oct 21, 2020, 1:51:03 PM10/21/20
to puppe...@googlegroups.com
Austin Blatt created an issue
 
PuppetDB / Improvement PDB-4937
Add a default statement timeout to user queries
Issue Type: Improvement Improvement
Assignee: Austin Blatt
Created: 2020/10/21 10:50 AM
Fix Versions: PDB 7.0.0
Labels: platform_7
Priority: Normal Normal
Reporter: Austin Blatt

Remaining questions

  • What is the default statement timeout for a query? 1min, 5min, 10min?
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Austin Blatt (Jira)

unread,
Oct 21, 2020, 1:52:04 PM10/21/20
to puppe...@googlegroups.com

Austin Blatt (Jira)

unread,
Oct 21, 2020, 1:53:03 PM10/21/20
to puppe...@googlegroups.com
Austin Blatt updated an issue
Change By: Austin Blatt
Fix Version/s: PDB 6.14.0

Austin Blatt (Jira)

unread,
Oct 21, 2020, 1:54:02 PM10/21/20
to puppe...@googlegroups.com
Austin Blatt updated an issue
Change By: Austin Blatt
Acceptance Criteria: * Query parameter to increase/decrease statement timeout for that query
* Config/env parameter to increase/decrease statement timeout for _all_ queries

* Disabled by a default value of 0 in PuppetDB 6.Y.0

Austin Blatt (Jira)

unread,
Oct 21, 2020, 2:28:04 PM10/21/20
to puppe...@googlegroups.com
Austin Blatt assigned an issue to Unassigned
Change By: Austin Blatt
Assignee: Austin Blatt

Austin Blatt (Jira)

unread,
Oct 21, 2020, 4:28:03 PM10/21/20
to puppe...@googlegroups.com

Austin Blatt (Jira)

unread,
Nov 4, 2020, 12:45:03 PM11/4/20
to puppe...@googlegroups.com
Austin Blatt updated an issue
Change By: Austin Blatt
Fix Version/s: PDB 6.14.0
Fix Version/s: PDB 7.0.0

Rob Browning (Jira)

unread,
Nov 5, 2020, 1:45:02 PM11/5/20
to puppe...@googlegroups.com
Rob Browning commented on Improvement PDB-4937
 
Re: Add a default statement timeout to user queries

We're setting this work aside until/unless we come up with a more sophisticated approach.  That is, with streaming responses, we can't return a custom status (say 503) to indicate a timeout once we've started streaming, and we might also want to provide a finer distinction than just 503.

In order to pursue this further, we might want to investigate chunked transfer encoding "trailing headers", where we could report a timeout.  Alternately, we could change our output format in order to allow us to send an indication of the timeout in the result stream itself that the client could then detect and handle.

The rest of the work went fairly smoothly, so were we able to come up with a palatable solution to this question, then we should be able to resume the effort.

Mihai Buzgau (Jira)

unread,
Nov 10, 2020, 11:38:03 AM11/10/20
to puppe...@googlegroups.com

Zachary Kent (Jira)

unread,
Nov 18, 2020, 2:51:01 PM11/18/20
to puppe...@googlegroups.com

David McTavish (Jira)

unread,
Feb 10, 2022, 9:41:01 AM2/10/22
to puppe...@googlegroups.com
David McTavish updated an issue
Change By: David McTavish
Story Points: 5
This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo

David McTavish (Jira)

unread,
Feb 10, 2022, 9:44:01 AM2/10/22
to puppe...@googlegroups.com

Alvin Rodis (Jira)

unread,
Oct 11, 2022, 3:33:01 PM10/11/22
to puppe...@googlegroups.com
Alvin Rodis updated an issue
Change By: Alvin Rodis
Labels: jira_escalated
This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo

Charlie Sharpsteen (Jira)

unread,
Oct 11, 2022, 3:33:02 PM10/11/22
to puppe...@googlegroups.com
Charlie Sharpsteen updated an issue
Change By: Charlie Sharpsteen
Zendesk Ticket Count: 1
Zendesk Ticket IDs: 49787

Charlie Sharpsteen (Jira)

unread,
Oct 11, 2022, 3:35:03 PM10/11/22
to puppe...@googlegroups.com
Charlie Sharpsteen commented on Improvement PDB-4937
 
Re: Add a default statement timeout to user queries

Re-opening this one. We've got a ticket where a user is reporting queries that persist for 1 day or longer and end up blocking other PuppetDB activities by holding locks. The root cause of this behavior is likely some other issue, but a default timeout for queries is a first line of defense that would help to blunt the impact.

Cas Donoghue (Jira)

unread,
Oct 20, 2022, 2:41:01 PM10/20/22
to puppe...@googlegroups.com
Cas Donoghue commented on Improvement PDB-4937

Then engineering work for this is pretty straight forward. We need to work with product (David Piekny ) and CS to come up with reasonable defaults and nail down which stream we target the work for. 

Austin Blatt (Jira)

unread,
Nov 3, 2022, 2:07:03 PM11/3/22
to puppe...@googlegroups.com

Austin Blatt (Jira)

unread,
Nov 3, 2022, 2:08:01 PM11/3/22
to puppe...@googlegroups.com
Austin Blatt assigned an issue to Unassigned
Change By: Austin Blatt
Assignee: Rob Browning

Austin Blatt (Jira)

unread,
Nov 3, 2022, 2:08:03 PM11/3/22
to puppe...@googlegroups.com

Austin Blatt (Jira)

unread,
Mar 1, 2023, 3:07:03 PM3/1/23
to puppe...@googlegroups.com
Austin Blatt updated an issue
Remaining questions

* What is the default statement timeout for a query? 1min, 5min, 10min?

JDBC does _not_ respect Thread interrupts so we could implement this by tracking running jdbc queries and calling JDBC's Statement.cancel() method.

Alternatively, and likely preferably, we can use statement timeouts to abort a query after a set time. Either by using setQueryTimeout (or setQueryTimeoutMs), and allow pgjdbc to handle things from there (see https://github.com/pgjdbc/pgjdbc/blob/5c78edb1412467636f996416ad37118f651db86e/pgjdbc/src/test/java/org/postgresql/test/jdbc2/StatementTest.java#L737-L762 for an example).

Or, we can set explicit statement timeouts in the SQL if the above does not work

{code}
SET statement_timeout TO 1
I puppetdb-> ;
SET

I puppetdb=> select pg_sleep(2);
ERROR:  canceling statement due to statement timeout
{code}

Austin Blatt (Jira)

unread,
Mar 1, 2023, 3:08:02 PM3/1/23
to puppe...@googlegroups.com
Austin Blatt updated an issue
Remaining questions

* What is the default statement timeout for a query? 1min, 5min, 10min?

JDBC does _not_ respect Thread interrupts so we could implement this by tracking running jdbc queries and calling JDBC's Statement.cancel() method.

Alternatively, and likely preferably, we can use statement timeouts to abort a query after a set time. Either by using setQueryTimeout (or setQueryTimeoutMs), and allow pgjdbc to handle things from there (see https://github.com/pgjdbc/pgjdbc/blob/5c78edb1412467636f996416ad37118f651db86e/pgjdbc/src/test/java/org/postgresql/test/jdbc2/StatementTest.java#L737-L762 for an example).

Or, we can set explicit statement timeouts in the SQL if the above does not work

{code}
puppetdb-> SET statement_timeout TO 1
I puppetdb->
;
SET

I
puppetdb=> select pg_sleep(2);
ERROR:  canceling statement due to statement timeout
{code}

Rob Browning (Jira)

unread,
Mar 8, 2023, 3:33:03 PM3/8/23
to puppe...@googlegroups.com
Rob Browning assigned an issue to Rob Browning
Change By: Rob Browning
Sprint: Skeletor 03/15/2023
Story Points: 1
Assignee: Rob Browning

Cas Donoghue (Jira)

unread,
Mar 15, 2023, 2:23:01 PM3/15/23
to puppe...@googlegroups.com
Cas Donoghue updated an issue
Change By: Cas Donoghue
Sprint: Skeletor 03/15/2023 , Skeletor 03/29/2023

Cas Donoghue (Jira)

unread,
Mar 29, 2023, 2:20:01 PM3/29/23
to puppe...@googlegroups.com
Cas Donoghue updated an issue
Change By: Cas Donoghue
Sprint: Skeletor 03/15/2023, Skeletor 03/29/2023 , Skeletor 04/12/2023

Nirupama Mantha (Jira)

unread,
Apr 3, 2023, 11:54:01 AM4/3/23
to puppe...@googlegroups.com

Nirupama Mantha (Jira)

unread,
Apr 3, 2023, 11:54:02 AM4/3/23
to puppe...@googlegroups.com

Austin Blatt (Jira)

unread,
Apr 12, 2023, 2:11:01 PM4/12/23
to puppe...@googlegroups.com
Austin Blatt updated an issue
Change By: Austin Blatt
Fix Version/s: PDB 8.0.0

Cas Donoghue (Jira)

unread,
Apr 12, 2023, 2:12:03 PM4/12/23
to puppe...@googlegroups.com
Cas Donoghue updated an issue
Change By: Cas Donoghue
Sprint: Skeletor 03/15/2023, Skeletor 03/29/2023, Skeletor 04/12/2023 , Skeletor 04/26/2024

Rob Browning (Jira)

unread,
Apr 21, 2023, 3:53:03 PM4/21/23
to puppe...@googlegroups.com
Rob Browning updated an issue
Change By: Rob Browning
Release Notes: Enhancement
Release Notes Summary: PuppetDB now supports query timeouts for queries to the `query/` endpoint via an [optional query parameter].  A [default] and a [maximum] can also be specified in the configuration.  The current default is ten minutes.

Rob Browning (Jira)

unread,
Apr 21, 2023, 3:54:03 PM4/21/23
to puppe...@googlegroups.com
Rob Browning updated an issue
Change By: Rob Browning
Epic Link: PDB PE - 4969 35436

Rob Browning (Jira)

unread,
Apr 21, 2023, 4:10:01 PM4/21/23
to puppe...@googlegroups.com
Rob Browning commented on Improvement PDB-4937
 
Re: Add a default statement timeout to user queries

In the end we implemented timeouts both on the pdb and pg sides, though the pg side timeouts aren't as precise because pg's statement_timeouts appear to apply to each underlying fetch batch for a top-level select, rather than the select as a whole. After some discussion, including CS, we also settled on a default statement timeout of 10m, which we expect to be long enough to avoid any significant disruption of existing environments (that aren't already likely in related trouble). Ideally, it might be even lower, something we can revisit later.

Assuming everything works right, that timeout should also substantially mitigate (or outright avoid) the causes of a number of serious escalations we've seen in the past, since no queries will be allowed to remain open for (sometimes) hours, unintentionally.

Reply all
Reply to author
Forward
0 new messages