mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-01 09:32:08 +00:00
sessionrecording: fix regression in recent http2 package change
In3f5c560fd4I 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 #17304 Updates3f5c560fd4Change-Id: I3602bafd07dc6548e2c62985af9ac0afb3a0e967 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
d5a40c01ab
commit
8996254647
@@ -405,10 +405,7 @@ func clientHTTP2(dialCtx context.Context, dial netx.DialFunc) *http.Client {
|
||||
return &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Protocols: &p,
|
||||
// Pretend like we're using TLS, but actually use the provided
|
||||
// DialFunc underneath. This is necessary to convince the transport
|
||||
// to actually dial.
|
||||
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
perAttemptCtx, cancel := context.WithTimeout(ctx, perDialAttemptTimeout)
|
||||
defer cancel()
|
||||
go func() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"golang.org/x/net/http2"
|
||||
"golang.org/x/net/http2/h2c"
|
||||
"tailscale.com/net/memnet"
|
||||
)
|
||||
|
||||
func TestConnectToRecorder(t *testing.T) {
|
||||
@@ -145,7 +146,14 @@ func TestConnectToRecorder(t *testing.T) {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
mux, uploadHash := tt.setup(t)
|
||||
|
||||
srv := httptest.NewUnstartedServer(mux)
|
||||
memNet := &memnet.Network{}
|
||||
ln := memNet.NewLocalTCPListener()
|
||||
|
||||
srv := &httptest.Server{
|
||||
Config: &http.Server{Handler: mux},
|
||||
Listener: ln,
|
||||
}
|
||||
|
||||
if tt.http2 {
|
||||
// Wire up h2c-compatible HTTP/2 server. This is optional
|
||||
// because the v1 recorder didn't support HTTP/2 and we try to
|
||||
@@ -159,10 +167,8 @@ func TestConnectToRecorder(t *testing.T) {
|
||||
srv.Start()
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
d := new(net.Dialer)
|
||||
|
||||
ctx := context.Background()
|
||||
w, _, errc, err := ConnectToRecorder(ctx, []netip.AddrPort{netip.MustParseAddrPort(srv.Listener.Addr().String())}, d.DialContext)
|
||||
w, _, errc, err := ConnectToRecorder(ctx, []netip.AddrPort{netip.MustParseAddrPort(ln.Addr().String())}, memNet.Dial)
|
||||
if err != nil {
|
||||
t.Fatalf("ConnectToRecorder: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user