SQL Queries Do Not Abide by RequestTimeout Setting

Description

Consider the following snippet. The SQL query calls a Postgres sleep function for 60 seconds.

If we uncomment the call to sleep(5 * 1000) then Request Timeout will kick in, but if the Query tag is reached, then RequestTimeout is ignored

IMO we should check the "Time to Live" (ttl) of the request before starting the query, and then set the query's timeout accordingly, i.e. pseudocode:

Also, if when the query returns the request has already timed out, then we do not see a RequestTimeout exception.

Environment

None

Activity

Show:

Joseph Gooch 10 November 2016 at 13:20

I haven't done extensive research, but I think the JDBC way of doing this would be to use Statement.cancel()... Otherwise my guess is different drivers would do different things, and you definitely want the driver to tell the server to cancel if the protocol allows it to do so.

That means having Lucee's Controller thread be smarter than just sending Thread.interrupt(). Perhaps cfquery needs to save a reference to the running Statement somewhere the Controller thread can access it - perhaps wrapped in a Strategy pattern... Something like RequestTimeoutAction.

Igal Sapir 10 November 2016 at 06:26

Nice. That's exactly what I had in mind.

Can't we cancel the query by calling interrupt() on the thread if it times out (from the Controller thread)? And that way avoid the driver's creation of a monitor thread?

Michael Offner 9 November 2016 at 09:22

search the code for "remaining", you will see that we did calculate the remaining request timeout and set this ALWAYS with statement. Problem was that some drivers start a new thread in that case, what caused problems if a lot of queries are executed.
so we disabled this for the moment and we have to review and make it smarter.

Joseph Gooch 8 November 2016 at 19:49

I usually don't use query timeouts because it spawns monitoring threads in the JDBC drivers. I'm used to the ACF behavior of once a query starts, you're in it until the query finishes. (at which point the next tag may throw a request timeout)

If we're going to look at something like this, we need also examine other areas where external data is requested... cfhttp, cfpop, cfimap, etc.

Further, were we to implement this, since this behavor is != ACF you'd definitely want to wrap this in a server option.

In my opinion I wouldn't use this; I'd use querytimeouts on the datasource instead. (or not at all, because I monitor my SQL query runtimes to detect SQL issues)

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Created 8 November 2016 at 07:24
Updated 24 October 2022 at 15:57