From dffe6ccf134781fdcc6cfd76c3193eac137354f3 Mon Sep 17 00:00:00 2001 From: Yondon Fu Date: Thu, 18 Nov 2021 18:10:02 -0500 Subject: [PATCH 1/3] server: Use http.Transport for HTTP client Replace http2.Transport to have option to downgrade from http2 if needed. --- server/segment_rpc.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/server/segment_rpc.go b/server/segment_rpc.go index 0aa4558deb..db8a5e0e48 100644 --- a/server/segment_rpc.go +++ b/server/segment_rpc.go @@ -22,7 +22,6 @@ import ( "github.com/livepeer/go-livepeer/net" "github.com/livepeer/lpms/ffmpeg" "github.com/livepeer/lpms/stream" - "golang.org/x/net/http2" ethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -44,15 +43,18 @@ var errProfile = errors.New("unrecognized encoder profile") var errDuration = errors.New("invalid duration") var errCapCompat = errors.New("incompatible capabilities") +var dialTimeout = 2 * time.Second + var tlsConfig = &tls.Config{InsecureSkipVerify: true} var httpClient = &http.Client{ - Transport: &http2.Transport{ + Transport: &http.Transport{ TLSClientConfig: tlsConfig, - DialTLS: func(network, addr string, cfg *tls.Config) (gonet.Conn, error) { - netDialer := &gonet.Dialer{ - Timeout: 2 * time.Second, - } - return tls.DialWithDialer(netDialer, network, addr, cfg) + DialTLSContext: func(ctx context.Context, network, addr string) (gonet.Conn, error) { + cctx, cancel := context.WithTimeout(ctx, dialTimeout) + defer cancel() + + tlsDialer := &tls.Dialer{Config: tlsConfig} + return tlsDialer.DialContext(cctx, network, addr) }, }, // Don't set a timeout here; pass a context to the request From dd00c917bb910603964e977492e226615240a0d6 Mon Sep 17 00:00:00 2001 From: Yondon Fu Date: Thu, 18 Nov 2021 19:03:26 -0500 Subject: [PATCH 2/3] server: Enable ForceAttemptHTTP2 on HTTP client --- server/segment_rpc.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/segment_rpc.go b/server/segment_rpc.go index db8a5e0e48..d89eee8ec3 100644 --- a/server/segment_rpc.go +++ b/server/segment_rpc.go @@ -56,6 +56,11 @@ var httpClient = &http.Client{ tlsDialer := &tls.Dialer{Config: tlsConfig} return tlsDialer.DialContext(cctx, network, addr) }, + // Required for the transport to try to upgrade to HTTP/2 if TLSClientConfig is non-nil or + // if custom dialers (i.e. via DialTLSContext) are used. This allows us to by default + // transparently support HTTP/2 while maintaining the flexibility to use HTTP/1 by running + // with GODEBUG=http2client=0 + ForceAttemptHTTP2: true, }, // Don't set a timeout here; pass a context to the request } From cd334a0c362ee7e033bcc99a2df730ee69487aa1 Mon Sep 17 00:00:00 2001 From: Yondon Fu Date: Fri, 19 Nov 2021 15:40:36 -0500 Subject: [PATCH 3/3] CHANGELOG_PENDING: Transparently support HTTP/2 While also allowing HTTP/1 via GODEBUG runtime flags. --- CHANGELOG_PENDING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 6d21213c4c..f5217c2229 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -16,6 +16,7 @@ - \#2022 Randomize selection of orchestrators in untrusted pool at a random frequency (@yondonfu) - \#2100 Check verified session first while choosing the result from multiple untrusted sessions (@leszko) - \#2103 Suspend sessions that did not pass p-hash verification (@leszko) +- \#2110 Transparently support HTTP/2 for segment requests while allowing HTTP/1 via GODEBUG runtime flags (@yondonfu) #### Orchestrator