-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interrupt/force close db connection when HTTP request finishes #394
Comments
We already have a way to cancel the pending statement (used for timeouts): It opens a new connection and sends the connection-specific secret token on it, which the server uses to abort the running statement (if there is any). If we would expose it on the connection interface, would that solve this issue? |
I've tried it too, but it wasn't really closing the connection. Thought it would be easier if I shared a reproduction case. I've created a repo with shelf+postgres and the abort utility middleware and pool extension. |
@isoos Would you be ok with a PR to discuss the flag that interrupts the running queries? Or are you confident the internal |
@davidmartos96: thank you for reminding me, and please do the PR :) Also: please bump the version + add a changelog entry for it. I'm a bit undecided if |
@isoos Yes, the changes let us achieve the connection abort behavior on connections tied to HTTP requests, like HTTP timeouts, avoiding filling up the connections on unexpectedly high volume of HTTP requests and where the db is getting unresponsive. I'll open a PR, we could discuss the name and how to test properly. |
@davidmartos96: my memory fails me here: is there anything pending left? |
@isoos There was some alternative you mentioned in this PR comment, which wouldn't close the connection, rather cancel the current statement. If you plan to add that maybe this issue could be updated or create a new one with the details. I don't think there is anything "pending" besides that comment. |
I think it should be as simple as the following code block:
But tests fail with uncaught exception(s) no matter how I tweak the error handling around it. The recently added strace tracking helped a bit, but I'm afraid this needs to have a deeper rewrite before we can add that cancellation. |
Is there any way to force close the database connection in a pool, even if there are queries running? The use case is to force close a connection obtained during an HTTP request in case of a timeout managed from the routes/middlewares layer in the HTTP server.
We've recently encountered with an issue on our server which made the database fill up the available connections because HTTP was timing out, but the database was still processing queries, even after the HTTP socket was closed.
We were able to achieve what we want with some tweaks in the postgres package, but I would like to hear your opinion in case you feel an alternative API would be better. Ideally without requiring extending a Pool implementation
Similar previous work:
grafana/grafana#22123
Postgres Dart fork with changes: https://github.com/davidmartos96/postgresql-dart/tree/feat/abort_conn
Custom pool, but it extends the PoolImplementation
The text was updated successfully, but these errors were encountered: