Skip to content

Commit 1a6c315

Browse files
committed
sessionrecording: fix regression in recent http2 package change
In 3f5c560 I changed to use std net/http's HTTP/2 support, instead of pulling in x/net/http2. But I forgot to update DialTLSContext to DialContext, which meant it was falling back to using the std net.Dialer for its dials, instead of the passed-in one. The tests only passed because they were using localhost addresses, so the std net.Dialer worked. But in prod, where a tsnet Dialer would be needed, it didn't work, and would time out for 10 seconds before resorting to the old protocol. So this fixes the tests to use an isolated in-memory network to prevent that class of problem in the future. With the test change, the old code fails and the new code passes. Thanks to @jasonodonnell for debugging! Updates tailscale#17304 Updates 3f5c560 Change-Id: I3602bafd07dc6548e2c62985af9ac0afb3a0e967 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> (cherry picked from commit 8996254)
1 parent 68cba30 commit 1a6c315

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

sessionrecording/connect.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,7 @@ func clientHTTP2(dialCtx context.Context, dial netx.DialFunc) *http.Client {
405405
return &http.Client{
406406
Transport: &http.Transport{
407407
Protocols: &p,
408-
// Pretend like we're using TLS, but actually use the provided
409-
// DialFunc underneath. This is necessary to convince the transport
410-
// to actually dial.
411-
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
408+
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
412409
perAttemptCtx, cancel := context.WithTimeout(ctx, perDialAttemptTimeout)
413410
defer cancel()
414411
go func() {

sessionrecording/connect_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"golang.org/x/net/http2"
2323
"golang.org/x/net/http2/h2c"
24+
"tailscale.com/net/memnet"
2425
)
2526

2627
func TestConnectToRecorder(t *testing.T) {
@@ -145,7 +146,14 @@ func TestConnectToRecorder(t *testing.T) {
145146
t.Run(tt.desc, func(t *testing.T) {
146147
mux, uploadHash := tt.setup(t)
147148

148-
srv := httptest.NewUnstartedServer(mux)
149+
memNet := &memnet.Network{}
150+
ln := memNet.NewLocalTCPListener()
151+
152+
srv := &httptest.Server{
153+
Config: &http.Server{Handler: mux},
154+
Listener: ln,
155+
}
156+
149157
if tt.http2 {
150158
// Wire up h2c-compatible HTTP/2 server. This is optional
151159
// because the v1 recorder didn't support HTTP/2 and we try to
@@ -159,10 +167,8 @@ func TestConnectToRecorder(t *testing.T) {
159167
srv.Start()
160168
t.Cleanup(srv.Close)
161169

162-
d := new(net.Dialer)
163-
164170
ctx := context.Background()
165-
w, _, errc, err := ConnectToRecorder(ctx, []netip.AddrPort{netip.MustParseAddrPort(srv.Listener.Addr().String())}, d.DialContext)
171+
w, _, errc, err := ConnectToRecorder(ctx, []netip.AddrPort{netip.MustParseAddrPort(ln.Addr().String())}, memNet.Dial)
166172
if err != nil {
167173
t.Fatalf("ConnectToRecorder: %v", err)
168174
}

0 commit comments

Comments
 (0)