node-pg and AbortController
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 :)
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.
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.
this is related to #773