Skip to content

Commit 2ee9048

Browse files
committed
TUN-7585: Remove h2mux compression
h2mux is already deprecated and will be eventually removed, in the meantime, the compression tests cause flaky failures. Removing them and the brotli code slims down our binaries and dependencies on CGO.
1 parent 2084a12 commit 2ee9048

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1
-33436
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/cloudflare/cloudflared
33
go 1.19
44

55
require (
6-
github.com/cloudflare/brotli-go v0.0.0-20191101163834-d34379f7ff93
76
github.com/cloudflare/golibs v0.0.0-20170913112048-333127dbecfc
87
github.com/coredns/coredns v1.10.0
98
github.com/coreos/go-oidc/v3 v3.6.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR
5959
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
6060
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
6161
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
62-
github.com/cloudflare/brotli-go v0.0.0-20191101163834-d34379f7ff93 h1:QrGfkZDnMxcWHaYDdB7CmqS9i26OAnUj/xcus/abYkY=
63-
github.com/cloudflare/brotli-go v0.0.0-20191101163834-d34379f7ff93/go.mod h1:QiTe66jFdP7cUKMCCf/WrvDyYdtdmdZfVcdoLbzaKVY=
6462
github.com/cloudflare/circl v1.2.1-0.20220809205628-0a9554f37a47 h1:YzpECHxZ9TzO7LpnKmPxItSd79lLgrR5heIlnqU4dTU=
6563
github.com/cloudflare/circl v1.2.1-0.20220809205628-0a9554f37a47/go.mod h1:qhx8gBILsYlbam7h09SvHDSkjpe3TfLA7b/z4rxJvkE=
6664
github.com/cloudflare/golibs v0.0.0-20170913112048-333127dbecfc h1:Dvk3ySBsOm5EviLx6VCyILnafPcQinXGP5jbTdHUJgE=

h2mux/h2_compressor_none.go renamed to h2mux/h2_compressor.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build !cgo
2-
// +build !cgo
3-
41
package h2mux
52

63
import (

h2mux/h2_compressor_brotli.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

h2mux/h2mux.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,7 @@ func Handshake(
135135
m.f.ReadMetaHeaders = hpack.NewDecoder(4096, func(hpack.HeaderField) {})
136136
// Initialise the settings to identify this connection and confirm the other end is sane.
137137
handshakeSetting := http2.Setting{ID: SettingMuxerMagic, Val: MuxerMagicEdge}
138-
compressionSetting := http2.Setting{ID: SettingCompression, Val: config.CompressionQuality.toH2Setting()}
139-
if CompressionIsSupported() {
140-
config.Log.Debug().Msg("muxer: Compression is supported")
141-
m.compressionQuality = config.CompressionQuality.getPreset()
142-
} else {
143-
config.Log.Debug().Msg("muxer: Compression is not supported")
144-
compressionSetting = http2.Setting{ID: SettingCompression, Val: 0}
145-
}
138+
compressionSetting := http2.Setting{ID: SettingCompression, Val: 0}
146139

147140
expectedMagic := MuxerMagicOrigin
148141
if config.IsClient {

h2mux/h2mux_test.go

Lines changed: 0 additions & 227 deletions
Original file line numberDiff line numberDiff line change
@@ -677,157 +677,6 @@ func AssertIfPipeReadable(t *testing.T, pipe io.ReadCloser) {
677677
}
678678
}
679679

680-
func TestMultipleStreamsWithDictionaries(t *testing.T) {
681-
l := zerolog.Nop()
682-
683-
for q := CompressionNone; q <= CompressionMax; q++ {
684-
htmlBody := `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"` +
685-
`"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">` +
686-
`<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">` +
687-
`<head>` +
688-
` <title>Your page title here</title>` +
689-
`</head>` +
690-
`<body>` +
691-
`<h1>Your major heading here</h1>` +
692-
`<p>` +
693-
`This is a regular text paragraph.` +
694-
`</p>` +
695-
`<ul>` +
696-
` <li>` +
697-
` First bullet of a bullet list.` +
698-
` </li>` +
699-
` <li>` +
700-
` This is the <em>second</em> bullet.` +
701-
` </li>` +
702-
`</ul>` +
703-
`</body>` +
704-
`</html>`
705-
706-
f := MuxedStreamFunc(func(stream *MuxedStream) error {
707-
var contentType string
708-
var pathHeader Header
709-
710-
for _, h := range stream.Headers {
711-
if h.Name == ":path" {
712-
pathHeader = h
713-
break
714-
}
715-
}
716-
717-
if pathHeader.Name != ":path" {
718-
panic("Couldn't find :path header in test")
719-
}
720-
721-
if strings.Contains(pathHeader.Value, "html") {
722-
contentType = "text/html; charset=utf-8"
723-
} else if strings.Contains(pathHeader.Value, "js") {
724-
contentType = "application/javascript"
725-
} else if strings.Contains(pathHeader.Value, "css") {
726-
contentType = "text/css"
727-
} else {
728-
contentType = "img/gif"
729-
}
730-
731-
_ = stream.WriteHeaders([]Header{
732-
{Name: "content-type", Value: contentType},
733-
})
734-
_, _ = stream.Write([]byte(strings.Replace(htmlBody, "paragraph", pathHeader.Value, 1) + stream.Headers[5].Value))
735-
736-
return nil
737-
})
738-
muxPair := NewCompressedMuxerPair(t, fmt.Sprintf("%s_%d", t.Name(), q), q, f)
739-
muxPair.Serve(t)
740-
741-
var wg sync.WaitGroup
742-
743-
paths := []string{
744-
"/html1",
745-
"/html2?sa:ds",
746-
"/html3",
747-
"/css1",
748-
"/html1",
749-
"/html2?sa:ds",
750-
"/html3",
751-
"/css1",
752-
"/css2",
753-
"/css3",
754-
"/js",
755-
"/js",
756-
"/js",
757-
"/js2",
758-
"/img2",
759-
"/html1",
760-
"/html2?sa:ds",
761-
"/html3",
762-
"/css1",
763-
"/css2",
764-
"/css3",
765-
"/js",
766-
"/js",
767-
"/js",
768-
"/js2",
769-
"/img1",
770-
}
771-
772-
wg.Add(len(paths))
773-
errorsC := make(chan error, len(paths))
774-
775-
for i, s := range paths {
776-
go func(index int, path string) {
777-
defer wg.Done()
778-
stream, err := muxPair.OpenEdgeMuxStream(
779-
[]Header{
780-
{Name: ":method", Value: "GET"},
781-
{Name: ":scheme", Value: "https"},
782-
{Name: ":authority", Value: "tunnel.otterlyadorable.co.uk"},
783-
{Name: ":path", Value: path},
784-
{Name: "cf-ray", Value: "378948953f044408-SFO-DOG"},
785-
{Name: "idx", Value: strconv.Itoa(index)},
786-
{Name: "accept-encoding", Value: "gzip, br"},
787-
},
788-
nil,
789-
)
790-
if err != nil {
791-
errorsC <- fmt.Errorf("error in OpenStream: %v", err)
792-
return
793-
}
794-
795-
expectBody := strings.Replace(htmlBody, "paragraph", path, 1) + strconv.Itoa(index)
796-
responseBody := make([]byte, len(expectBody)*2)
797-
n, err := stream.Read(responseBody)
798-
if err != nil {
799-
errorsC <- fmt.Errorf("stream %d error from (*MuxedStream).Read: %s", stream.streamID, err)
800-
return
801-
}
802-
if n != len(expectBody) {
803-
errorsC <- fmt.Errorf("stream %d expected response body to have %d bytes, got %d", stream.streamID, len(expectBody), n)
804-
return
805-
}
806-
if string(responseBody[:n]) != expectBody {
807-
errorsC <- fmt.Errorf("stream %d expected response body %s, got %s", stream.streamID, expectBody, responseBody[:n])
808-
return
809-
}
810-
}(i, s)
811-
}
812-
813-
wg.Wait()
814-
close(errorsC)
815-
testFail := false
816-
for err := range errorsC {
817-
testFail = true
818-
l.Error().Msgf("%s", err)
819-
}
820-
if testFail {
821-
t.Fatalf("TestMultipleStreams failed")
822-
}
823-
824-
originMuxMetrics := muxPair.OriginMux.Metrics()
825-
if q > CompressionNone && originMuxMetrics.CompBytesBefore.Value() <= 10*originMuxMetrics.CompBytesAfter.Value() {
826-
t.Fatalf("Cross-stream compression is expected to give a better compression ratio")
827-
}
828-
}
829-
}
830-
831680
func sampleSiteHandler(files map[string][]byte) MuxedStreamFunc {
832681
return func(stream *MuxedStream) error {
833682
var contentType string
@@ -914,82 +763,6 @@ func loadSampleFiles(paths []string) (map[string][]byte, error) {
914763
return files, nil
915764
}
916765

917-
func TestSampleSiteWithDictionaries(t *testing.T) {
918-
paths := []string{
919-
"./sample/index.html",
920-
"./sample/index2.html",
921-
"./sample/index1.html",
922-
"./sample/ghost-url.min.js",
923-
"./sample/jquery.fitvids.js",
924-
"./sample/index1.html",
925-
"./sample/index2.html",
926-
"./sample/index.html",
927-
}
928-
files, err := loadSampleFiles(paths)
929-
assert.NoError(t, err)
930-
931-
for q := CompressionNone; q <= CompressionMax; q++ {
932-
muxPair := NewCompressedMuxerPair(t, fmt.Sprintf("%s_%d", t.Name(), q), q, sampleSiteHandler(files))
933-
muxPair.Serve(t)
934-
935-
var wg sync.WaitGroup
936-
errC := make(chan error, len(paths))
937-
938-
wg.Add(len(paths))
939-
for _, s := range paths {
940-
go func(path string) {
941-
defer wg.Done()
942-
errC <- sampleSiteTest(muxPair, path, files)
943-
}(s)
944-
}
945-
946-
wg.Wait()
947-
close(errC)
948-
949-
for err := range errC {
950-
assert.NoError(t, err)
951-
}
952-
953-
originMuxMetrics := muxPair.OriginMux.Metrics()
954-
if q > CompressionNone && originMuxMetrics.CompBytesBefore.Value() <= 10*originMuxMetrics.CompBytesAfter.Value() {
955-
t.Fatalf("Cross-stream compression is expected to give a better compression ratio")
956-
}
957-
}
958-
}
959-
960-
func TestLongSiteWithDictionaries(t *testing.T) {
961-
paths := []string{
962-
"./sample/index.html",
963-
"./sample/index1.html",
964-
"./sample/index2.html",
965-
"./sample/ghost-url.min.js",
966-
"./sample/jquery.fitvids.js",
967-
}
968-
files, err := loadSampleFiles(paths)
969-
assert.NoError(t, err)
970-
for q := CompressionNone; q <= CompressionMedium; q++ {
971-
muxPair := NewCompressedMuxerPair(t, fmt.Sprintf("%s_%d", t.Name(), q), q, sampleSiteHandler(files))
972-
muxPair.Serve(t)
973-
974-
rand.Seed(time.Now().Unix())
975-
976-
tstLen := 500
977-
errGroup, _ := errgroup.WithContext(context.Background())
978-
for i := 0; i < tstLen; i++ {
979-
errGroup.Go(func() error {
980-
path := paths[rand.Int()%len(paths)]
981-
return sampleSiteTest(muxPair, path, files)
982-
})
983-
}
984-
assert.NoError(t, errGroup.Wait())
985-
986-
originMuxMetrics := muxPair.OriginMux.Metrics()
987-
if q > CompressionNone && originMuxMetrics.CompBytesBefore.Value() <= 10*originMuxMetrics.CompBytesAfter.Value() {
988-
t.Fatalf("Cross-stream compression is expected to give a better compression ratio")
989-
}
990-
}
991-
}
992-
993766
func BenchmarkOpenStream(b *testing.B) {
994767
const streams = 5000
995768
for i := 0; i < b.N; i++ {

0 commit comments

Comments
 (0)