Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect SETTINGS_HEADER_TABLE_SIZE http2 setting #2045

Merged
merged 4 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions transport/controlbuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import (
"golang.org/x/net/http2/hpack"
)

var updateHeaderTblSize = func(e *hpack.Encoder, v uint32) {
e.SetMaxDynamicTableSizeLimit(v)
}

type itemNode struct {
it interface{}
next *itemNode
Expand Down Expand Up @@ -664,6 +668,8 @@ func (l *loopyWriter) applySettings(ss []http2.Setting) error {
}
}
}
case http2.SettingHeaderTableSize:
updateHeaderTblSize(l.hEnc, s.Val)
}
}
return nil
Expand Down
110 changes: 110 additions & 0 deletions transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2086,3 +2086,113 @@ func runPingPongTest(t *testing.T, msgSize int) {
}
}
}

type tableSizeLimit struct {
mu sync.Mutex
limits []uint32
}

func (t *tableSizeLimit) add(limit uint32) {
t.mu.Lock()
t.limits = append(t.limits, limit)
t.mu.Unlock()
}

func (t *tableSizeLimit) getLen() int {
t.mu.Lock()
defer t.mu.Unlock()
return len(t.limits)
}

func (t *tableSizeLimit) getIndex(i int) uint32 {
t.mu.Lock()
defer t.mu.Unlock()
return t.limits[i]
}

func TestHeaderTblSize(t *testing.T) {
limits := &tableSizeLimit{}
updateHeaderTblSize = func(e *hpack.Encoder, v uint32) {
e.SetMaxDynamicTableSizeLimit(v)
limits.add(v)
}
defer func() {
updateHeaderTblSize = func(e *hpack.Encoder, v uint32) {
e.SetMaxDynamicTableSizeLimit(v)
}
}()

server, ct := setUp(t, 0, math.MaxUint32, normal)
defer ct.Close()
defer server.stop()
_, err := ct.NewStream(context.Background(), &CallHdr{})
if err != nil {
t.Fatalf("failed to open stream: %v", err)
}

var svrTransport ServerTransport
var i int
for i = 0; i < 1000; i++ {
server.mu.Lock()
if len(server.conns) != 0 {
server.mu.Unlock()
break
}
server.mu.Unlock()
time.Sleep(10 * time.Millisecond)
continue
}
if i == 1000 {
t.Fatalf("unable to create any server transport after 10s")
}

for st := range server.conns {
svrTransport = st
break
}
svrTransport.(*http2Server).controlBuf.put(&outgoingSettings{
ss: []http2.Setting{
{
ID: http2.SettingHeaderTableSize,
Val: uint32(100),
},
},
})

for i = 0; i < 1000; i++ {
if limits.getLen() != 1 {
time.Sleep(10 * time.Millisecond)
continue
}
if val := limits.getIndex(0); val != uint32(100) {
t.Fatalf("expected limits[0] = 100, got %d", val)
}
break
}
if i == 1000 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing i is local to the for loop above.

t.Fatalf("expected len(limits) = 1 within 10s, got != 1")
}

ct.(*http2Client).controlBuf.put(&outgoingSettings{
ss: []http2.Setting{
{
ID: http2.SettingHeaderTableSize,
Val: uint32(200),
},
},
})

for i := 0; i < 1000; i++ {
if limits.getLen() != 2 {
time.Sleep(10 * time.Millisecond)
continue
}
if val := limits.getIndex(1); val != uint32(200) {
t.Fatalf("expected limits[1] = 200, got %d", val)
}
break
}
if i == 1000 {
t.Fatalf("expected len(limits) = 2 within 10s, got != 2")
}
}