postgresql-dart icon indicating copy to clipboard operation
postgresql-dart copied to clipboard

connection.query timeout do not work

Open bubnenkoff opened this issue 4 years ago • 5 comments

timeoutInSeconds in:

connection.query(sqlQuery, timeoutInSeconds: 3600)

do not work, My code is fall with timeout exception: Future not compeleted on long queries.

query timeouts sets only if they are setting on connection:

connection = PostgreSQLConnection('localhost', 5432, 'test', username: 'postgres', password: '12345', queryTimeoutInSeconds: 3600); // here 

But setting in connection.query are should work because:

timeoutInSeconds ??= _connection.queryTimeoutInSeconds;

bubnenkoff avatar Sep 06 '21 09:09 bubnenkoff

@bubnenkoff I don't see any trivial bug in the timeout parameter handling. Is there any way you could provide a reproducible code with the related DB setup?

isoos avatar Sep 06 '21 20:09 isoos

To reproduce you need set long timeout here:

connection = PostgreSQLConnection('localhost', 5432, 'test', username: 'postgres', password: '12345', queryTimeoutInSeconds: 3600); //  here

And to try run long request here:

connection.query(sqlQuery) // some long request that run for example 1 minute

In result you will get error:

Future not completed

See code here https://stackoverflow.com/questions/69041494/timeoutexception-on-query-cache-class I found this issue when debug code example above.

bubnenkoff avatar Sep 07 '21 12:09 bubnenkoff

@bubnenkoff I'm not able to check this until later, to help the debugging, could you check it at what pg_sleep(<number>) will throw it an exception? e.g. connection.query('SELECT 1, pg_sleep(2)') will likely succeed, how about connection.query('SELECT 1, pg_sleep(31)'), connection.query('SELECT 1, pg_sleep(61)'), connection.query('SELECT 1, pg_sleep(601)')?

isoos avatar Sep 07 '21 12:09 isoos

I am having the same issue here. It breaks at 30 seconds.

TimeoutException after 0:00:30.000000: Future not completed

I am using both the timeoutInSeconds property, and as I am using futures, I am setting the timeout of the futures to 2 hours.

PostgreSQLConnection omtConnection = PostgreSQLConnection(
    config.omt_database!.host!, config.omt_database!.port!, config.omt_database!.databaseName!,
    username: config.omt_database!.username,
    password: config.omt_database!.password,
    useSSL: config.omt_database!.ssl,
    allowClearTextPassword: config.omt_database!.allowClearTextPassword,
    queryTimeoutInSeconds: 7200
);

var query = await omtConnection.query(getPatientsSql).timeout(Duration(hours: 2));

Everything is in a try catch block, it gets the error, but there is no stack information. Could it be related to any configuration in the server instead of the library?

@isoos if you point me to the right place of the library to narrow the search I can take a look

pedropastor avatar Nov 30 '23 10:11 pedropastor

@pedropastor: the package has moved to a new repository (and new versions). Please use that for further help.

isoos avatar Nov 30 '23 10:11 isoos