Knex .timeout(ms, {cancel: boolean}) use cancel instead of terminate for postgresql #3518
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request is to fix a bug that I have with knex on postgresql (knex version :
0.20.1
, node-pg version :7.12.1
, postgresql database version :11
The bug is on the timeout feature of knex.
When I try to cancel a postgresql request (with the knex.timeout and the cancel option set to true) the request is correctly canceled but if I try to run a request just after the canceled one sometimes I have this error :
The bug is kind of random but I can easily reproduce it when doing this :
I try to get some
select *
from a postgresql table (you should be abble to reproduce it), I join on the same table than the select to have a huge query that takes time (it seems that the problem is very rare on small query with small timeout or with aselect pg_sleep(10)
I see the
the bug is here
console.log many times, not always but many times with the error I put just above...I guess it is because of the use of
pg_terminate_backend
method to cancel the query which totaly destroyed the connection and for the second request I get something that is altered by this terminate thing.If I use
pg_cancel_backend
instead I have no problem at all, everything works fine and the request is well canceled in postgresql database.esvinson added a comment on 26 Sep 2018 on the pull request (related with timeout on postgresql : #2636 ) asking why we used
pg_terminate_backend
instead ofpg_cancel_backend
and he's probably right... there is no need here to use the terminate instead of the cancel and it is working fine with the cancel...