From 0e0bf2a9fdb1f21b740804aa949b7dae90de3063 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 20 May 2021 15:44:29 -0700 Subject: [PATCH] set initial window size to spec value (256 kB), remove config option --- const.go | 5 +++-- mux.go | 29 ++++++++++++----------------- session_test.go | 2 +- stream.go | 1 - 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/const.go b/const.go index c326f96..dfb0add 100644 --- a/const.go +++ b/const.go @@ -113,8 +113,9 @@ const ( ) const ( - // initialStreamWindow is the initial stream window size - initialStreamWindow uint32 = 64 * 1024 + // initialStreamWindow is the initial stream window size. + // It's not an implementation choice, the value defined in the specification. + initialStreamWindow uint32 = 256 * 1024 maxStreamWindow uint32 = 16 * 1024 * 1024 ) diff --git a/mux.go b/mux.go index 8113646..ae4655d 100644 --- a/mux.go +++ b/mux.go @@ -31,10 +31,6 @@ type Config struct { // an expectation that things will move along quickly. ConnectionWriteTimeout time.Duration - // InitialStreamWindowSize is used to control the initial - // window size that we allow for a stream. - InitialStreamWindowSize uint32 - // MaxStreamWindowSize is used to control the maximum // window size that we allow for a stream. MaxStreamWindowSize uint32 @@ -60,17 +56,16 @@ type Config struct { // DefaultConfig is used to return a default configuration func DefaultConfig() *Config { return &Config{ - AcceptBacklog: 256, - PingBacklog: 32, - EnableKeepAlive: true, - KeepAliveInterval: 30 * time.Second, - ConnectionWriteTimeout: 10 * time.Second, - InitialStreamWindowSize: initialStreamWindow, - MaxStreamWindowSize: maxStreamWindow, - LogOutput: os.Stderr, - ReadBufSize: 4096, - MaxMessageSize: 64 * 1024, - WriteCoalesceDelay: 100 * time.Microsecond, + AcceptBacklog: 256, + PingBacklog: 32, + EnableKeepAlive: true, + KeepAliveInterval: 30 * time.Second, + ConnectionWriteTimeout: 10 * time.Second, + MaxStreamWindowSize: maxStreamWindow, + LogOutput: os.Stderr, + ReadBufSize: 4096, + MaxMessageSize: 64 * 1024, + WriteCoalesceDelay: 100 * time.Microsecond, } } @@ -82,8 +77,8 @@ func VerifyConfig(config *Config) error { if config.KeepAliveInterval == 0 { return fmt.Errorf("keep-alive interval must be positive") } - if config.MaxStreamWindowSize < config.InitialStreamWindowSize { - return errors.New("MaxStreamWindowSize must be larger than the InitialStreamWindowSize") + if config.MaxStreamWindowSize < initialStreamWindow { + return errors.New("MaxStreamWindowSize must be larger than the initialStreamWindow (256 kB)") } if config.MaxMessageSize < 1024 { return fmt.Errorf("MaxMessageSize must be greater than a kilobyte") diff --git a/session_test.go b/session_test.go index d6bcca3..0cb9017 100644 --- a/session_test.go +++ b/session_test.go @@ -1194,7 +1194,7 @@ func TestSession_PartialReadWindowUpdate(t *testing.T) { sendWindow := atomic.LoadUint32(&wr.sendWindow) if sendWindow != initialStreamWindow { - t.Errorf("sendWindow: exp=%d, got=%d", client.config.InitialStreamWindowSize, sendWindow) + t.Errorf("sendWindow: exp=%d, got=%d", initialStreamWindow, sendWindow) } n, err := wr.Write(make([]byte, flood)) diff --git a/stream.go b/stream.go index 2f95cc9..06ae368 100644 --- a/stream.go +++ b/stream.go @@ -52,7 +52,6 @@ type Stream struct { // newStream is used to construct a new stream within // a given session for an ID func newStream(session *Session, id uint32, state streamState) *Stream { - initialStreamWindow := session.config.InitialStreamWindowSize s := &Stream{ id: id, session: session,