Repository navigation
net/http: add Request.Cancel - #717
Merged
Merged
Conversation
This was referenced Oct 27, 2026
Port Go's deprecated Request.Cancel channel. The client's setRequestCancel now makes its own channel and timer for a request that has one or a round tripper it doesn't know, the transport turns the channel into context cancellation like Go's awaitLegacyCancel, and the HTTP/2 transport watches it on each wait. Port TestTransportCancelRequest's three variants in HTTP/1 mode.
A test that skips in -short mode never returns to cancel_test_run, so the arena it set up leaked under ASan.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Go's deprecated
Request.Cancelchannel, from Go 1.27.3'snet/http. It was one of the last gaps inburrow-coveragefornet/http.Request.CancelHttpRequest.cancel, aChan *, NULL for nonesetRequestCancel, the part forRequest.Canceland unknown round tripperscl_send_request, with the goroutinecl_send_timerawaitLegacyCanceltp_await_legacy_cancelreq.Cancelcases in the HTTP/2 transport's selectshttp2_transport.cThe client now does what Go's
setRequestCanceldoes when a request has a deadline and either has aCancelchannel or goes to a round tripper the client doesn't know. It swaps in its own channel and starts a timer. When the user's channel closes or the timer fires, it closes that channel and callsCancelRequeston anHttpTransport. A redirect keeps the original request's channel.The HTTP/1 transport turns the channel into context cancellation with
errRequestCanceled, like Go'sawaitLegacyCancel. The HTTP/2 transport checks it in every select where Go's does.Two things are "Not in Go" and are there because C has no garbage collector. The client waits for its timer goroutine before it frees the channels, and the transport waits for
tp_await_legacy_cancelbefore it frees the call's context. The doc comment says the channel has to outlive the response's body for the same reason.Tests
TestTransportCancelRequestis intests/http_transport_test.c, with Go'scancelTestandrunCancelTestported as a kind plus three helpers. It runs the TransportCancel, RequestCancel and ContextCancel variants in HTTP/1 mode only, like the rest of that file. Go's last step waits forNumPendingRequestsForTestingto reach 0. Burrow's transport has nothing like it, so that step is left out and a comment says so.Results
None of the servers has the 5G free I need before starting a job, so none of this has been built or run there. CI's run is the first one. Locally, the changed files pass the syntax check with
-Wall -Wextra, clang-format, check-headers and check-errout, and clang-tidy flags nothing in the changed lines.burrow-coveragehasnet/httpat 483/505 on this branch.