My server uses Actix-web Rust framework. It functions as a proxy, forwarding client requests to a backend (PostgreSQL), and returns the responses.
Due to the nature of my service (map tile server), the client often cancels the GET
requests using the browser's fetch(..., {AbortSignal}). I suspect the actual socket connection remains, just one specific fetch
is aborted.
How can I catch such request aborts in Actix-web, and notify my backend to stop handling it as well?
Hypothetical code:
/// Run a backend query, and if the client aborts early,
/// make sure to abort the backend query too
#[route("/foo")]
async fn get_data(
req: HttpRequest,
state: Data<AppState>,
) -> Result<HttpResponse, Error> {
let cancel_token = CancellationToken::new();
req.on_client_cancel(|| { // <-- this api doesn't exist
cancel_token.abort();
});
backend.query(..., cancel_token).await
}