Repository navigation
net/http: port ClientConn and Transport.NewClientConn - #721
Merged
Merged
Conversation
Port Go 1.27's clientconn.go: Transport.NewClientConn dials one HTTP/1 or HTTP/2 connection the caller manages, with Available, InFlight, Reserve, Release, Err, Close and a state hook. The HTTP/1 side is a persistConn with the clientConn flag, the HTTP/2 side is Go's NetHTTPClientConn, and both sit behind one small vtable. The tests are clientconn_test.go's six, in h1 and h2 modes.
23 of 27 tasks
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 is
A port of Go 1.27's
clientconn.go.http_transport_new_client_conndials a single HTTP/1 or HTTP/2 connection that the caller manages, outside the transport's pool. Every method of Go'sClientConnis here, along with the six tests fromclientconn_test.go. This is part of #6.(*Transport).NewClientConnhttp_transport_new_client_conn(*ClientConn).RoundTriphttp_client_conn_round_tripAvailable,InFlighthttp_client_conn_available,http_client_conn_in_flightReserve,Releasehttp_client_conn_reserve,http_client_conn_releaseErr,Closehttp_client_conn_err,http_client_conn_closeSetStateHookhttp_client_conn_set_state_hookHow it fits together
Go keeps a small
genericClientConninterface betweenClientConnand the two protocols, and this port uses a vtable for it.persistConndialed in client conn mode, so it never goes back to the idle pool. The new methods are Go'shttp1ClientConnones (availability throughavailch,reserved,inFlight).NetHTTPClientConn, made byburrow__http2_transport_new_client_connwithstrictMaxConcurrentStreamsset. Go calls the internal state hook from four places (closeConn,cleanupWriteRequestafterdoneccloses, settings processing, and the ping ack), and so does this port.maybeRunStateHookandshouldRunStateHookkeep Go's debounce. The first call is synchronous, and any changes after it are picked up by one goroutine.Not in Go
C has no garbage collector, so the caller frees the conn with
http_client_conn_free. That has to happen before the transport is freed, and never from inside the state hook. TheHttpClientConnis refcounted:Free waits for any running hook to finish before it closes the connection. If no goroutine can be started, the hook runs inline. When request validation fails, round trip closes the body, the same way a RoundTripper does.
tools/burrow-coveragegets afunc(*ClientConn)entry so thatHttpClientConnStateHookcounts as SetStateHook's parameter type.Tests
tests/http_clientconn_test.chas all six tests. Each one runs in h1 and h2 mode, and the five that userunSynctestin Go use synctest here. The test server is the in-memory httptest one, somode_addris a fixedexample.tldaddress and not a listener's. That part is marked Not in Go.I ran these on a Linux box with clang, building
http_clientconn_test,http_transport_test,http2_transport_test,http_client_testandhttptest_test:-test.short-test.short-test.short-test.count=5http_clientconn_test -test.count=5, 3 timesThe static checks (banned, headers, annotations, alloc, globals, statics, fips-module) passed there too. On the Mac, coverage now reports net/http with no signature differences, and
doc --checkand the cheatsheet check pass.