Skip to content

net/http: add Request.Cancel - #717

Merged
tamnd merged 2 commits into
mainfrom
req-cancel
Oct 27, 2026
Merged

tamnd merged 2 commits into
mainfrom
req-cancel

Conversation

@tamnd

@tamnd tamnd commented Oct 27, 2026

Copy link
Copy Markdown
Owner

What this adds

Go's deprecated Request.Cancel channel, from Go 1.27.3's net/http. It was one of the last gaps in burrow-coverage for net/http.

Go burrow
Request.Cancel HttpRequest.cancel, a Chan *, NULL for none
setRequestCancel, the part for Request.Cancel and unknown round trippers cl_send_request, with the goroutine cl_send_timer
awaitLegacyCancel tp_await_legacy_cancel
the req.Cancel cases in the HTTP/2 transport's selects the same cases in http2_transport.c

The client now does what Go's setRequestCancel does when a request has a deadline and either has a Cancel channel 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 calls CancelRequest on an HttpTransport. A redirect keeps the original request's channel.

The HTTP/1 transport turns the channel into context cancellation with errRequestCanceled, like Go's awaitLegacyCancel. 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_cancel before it frees the call's context. The doc comment says the channel has to outlive the response's body for the same reason.

Tests

TestTransportCancelRequest is in tests/http_transport_test.c, with Go's cancelTest and runCancelTest ported 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 for NumPendingRequestsForTesting to 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-coverage has net/http at 483/505 on this branch.

@tamnd tamnd added port Porting a standard library package, or part of one area: pure Packages with no OS and no concurrency: strings through regexp labels Oct 27, 2026
tamnd added 2 commits October 27, 2026 21:15
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.
@tamnd
tamnd merged commit d12bece into main Oct 27, 2026
43 of 47 checks passed
@tamnd
tamnd deleted the req-cancel branch October 27, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: pure Packages with no OS and no concurrency: strings through regexp port Porting a standard library package, or part of one

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant