node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

node-pg and AbortController

Open AxelTerizaki opened this issue 4 years ago • 3 comments

As of Node 15 you can use AbortController to abort promises. From what I gather, this is not yet supported by node-postgres, and I would like to know if this is a planned feature?

Or is there a way I can abort a database query?

Thanks in advance :)

AxelTerizaki avatar Sep 28 '21 13:09 AxelTerizaki

I don't think postgres supports canceling / aborting a specific query.

Is the best we can do is to tell postgres to try to cancel whatever query is being executed on a given connection, and pause sending new queries to that connection while we wait for the cancelation to finish?

This requires a new connection ideally from outside of the pool used for the query to be canceled.

I'm not sure how the library currently handles enqueued (unsent) queries on a client / pool, but the cancelation mechanism would probably have to hook into there.

boromisp avatar Sep 28 '21 16:09 boromisp

This might be relevant: https://www.postgresql.org/docs/14/runtime-config-connection.html#GUC-CLIENT-CONNECTION-CHECK-INTERVAL. In certain cases - depending on the environment - you can configure postgres 14 to automatically cancel queries it the client closes the connection. This method has different trade-offs: it doesn't require an extra connection, you just nuke the one executing the offending query. OTOH you can't return that connection to the pool.

boromisp avatar Oct 05 '21 14:10 boromisp

this is related to #773

tmtron avatar Dec 20 '21 08:12 tmtron