Skip to content

Conversation

@mladedav
Copy link
Contributor

Motivation

When a request is created and possibly partially sent, but the future is dropped before being polled to completion, then on_request_end is not called.

Solution

This adds another method for this scenario so that either on_request_end or on_request_cancelled is always called if the middleware finishes.

The method has a provided implementation so that it is not a breaking change.

This new method is different from the other two in that it does not take &mut Extensions. This is due to technical difficulities as I would need to keep the mutable reference in the drop guard, but at the same time the future that has access to the same mutable reference would be run. I don't think there is a way to solve this without unsafe and raw pointers (or maybe self-referential structs). So I've decided not to provide the extensions instead.

Alternatives

  • We can add another case to the Error enum for this and reuse on_request_end. This would also force us to solve the issue around the &mut Extensions so I think this would also require unsafe code.

@mladedav mladedav requested a review from a team as a code owner October 29, 2025 12:39
@mladedav mladedav changed the title feat: add method for handling cancelled requests reqwest-tracing: add method for handling cancelled requests Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant