stablekernel / postgresql-dart

Dart PostgreSQL driver: supports extended query format, binary protocol and statement reuse.
https://www.dartdocs.org/documentation/postgres/latest
BSD 3-Clause "New" or "Revised" License
129 stars 32 forks source link

connection.query timeout do not work #167

Open bubnenkoff opened 3 years ago

bubnenkoff commented 3 years ago

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;
isoos commented 3 years ago

@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?

bubnenkoff commented 3 years ago

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.

isoos commented 3 years ago

@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)')?

pedropastor commented 9 months ago

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

isoos commented 9 months ago

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