martin
martin copied to clipboard
add a proper way to handle long-running and interrupted queries
Martin may become unresponsive while PostgreSQL is handling a lot of long-running SQL queries. Some frontends like Nginx may also cancel requests based on timeout, but these requests might still be running as queries in PostgreSQL.
We need a way to set a timeout for such requests, so we can cancel queries in the PostgreSQL.
There might be a way to detect when the connection is dropped -- similar to how it is described for the Axum framework here. If the connection is indeed dropped by the fetch API signal, we might be able to utilize the Tokio-postgres CancelToken
Something like this:
let conn = get_connection(&self.pool).await?;
let cancel_token = conn.cancel_token();
let cancel = cancel_token.cancel_query(tls_info);