brianc / node-postgres

PostgreSQL client for node.js.
https://node-postgres.com
MIT License
12.04k stars 1.21k forks source link

Improve race condition in pg-native cancel test #3234

Closed brianc closed 4 weeks ago

brianc commented 4 weeks ago

Since the pg-native tests run more now the race condition is more apparent. In CI I think the query doesn't have time to get to the backend sometimes before the cancel is executed. This should give it more time. Still somewhat of a race condition possible, but much less likely. Also removed unneeded non-dev dependency in pg-native.

brianc commented 4 weeks ago

ohhhh good point about the pg_sleep being in seconds - totally forgot about that. I'll let the 100ms timeout ride for now to send the cancel (as before there was NO timeout) and if it bugs again I'll increase it. Appreciate the eyes on things!! :heart: hope everything is groovy & you can make it down yonder soon :)

On Tue, Jun 4, 2024 at 4:00 PM Sehrope Sarkuni @.***> wrote:

@.**** commented on this pull request.

In packages/pg-native/test/cancel.js https://github.com/brianc/node-postgres/pull/3234#discussion_r1626597870 :

@@ -5,13 +5,15 @@ describe('cancel query', function () { it('works', function (done) { var client = new Client() client.connectSync()

  • client.query('SELECT pg_sleep(100);', function (err) {
  • client.query('SELECT pg_sleep(1000);', function (err) {

The arg to pg_sleep(...) is seconds so changing from 100 to 1000 would not be relevant.

I think what you need to do is raise the 100 milliseconds (not seconds) below on line 16 to give the DB more time to start this command. The race that's happening is that the query has not started before 100ms, not that it's not running for long enough.

— Reply to this email directly, view it on GitHub https://github.com/brianc/node-postgres/pull/3234#pullrequestreview-2097378153, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMHIKE35SJPSZT6SGFZRLZFYTHDAVCNFSM6AAAAABIY35KCOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDAOJXGM3TQMJVGM . You are receiving this because you modified the open/close state.Message ID: @.***>