Skip to content

Commit

Permalink
fix: potential memory pressure on server side
Browse files Browse the repository at this point in the history
This fix changes the default configuration of the HTTP/2 transport to advertise an unlimited value to the peer for SETTINGS_MAX_HEADER_LIST_SIZE (0x6). This configuration basically disables sending the setting at all. So the server uses its default settings.

As some servers like Jetty allocate buffers in size of this setting, this can lead to memory pressure or even OOM errors when the server is not configured properly.

see https://www.ietf.org/archive/id/draft-ietf-httpbis-http2bis-07.html#section-6.5.2-2.11
  • Loading branch information
jrauschenbusch authored and Jochen Rauschenbusch committed Feb 6, 2025
1 parent 6446db6 commit 7c3e2fd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/pkg/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ func NewClient(host string, insecure bool, timeoutMilliseconds int, protocol Pro
switch protocol {
case HTTP2:
client.Transport = &http2.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
MaxHeaderListSize: 0xffffffff, // avoid sending SETTINGS_MAX_HEADER_LIST_SIZE (0x6) via SETTINGS frame
}
case H2C:
client.Transport = &http2.Transport{
AllowHTTP: true,
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
return net.Dial(network, addr)
},
MaxHeaderListSize: 0xffffffff, // avoid sending SETTINGS_MAX_HEADER_LIST_SIZE (0x6) via SETTINGS frame
}
default:
client.Transport = &http.Transport{
Expand All @@ -80,7 +82,7 @@ func (c Client) SendRequest(method, path string, headers map[string]string, requ
if requestBody != nil {
body = bytes.NewBufferString(*requestBody)
}

url := fmt.Sprintf("%s/%s", c.host, strings.TrimLeft(path, "/"))
req, err := http.NewRequest(method, url, body)
if err != nil {
Expand All @@ -89,7 +91,7 @@ func (c Client) SendRequest(method, path string, headers map[string]string, requ
}
if req.Body != nil {
defer req.Body.Close()
}
}
for k, v := range headers {
if strings.EqualFold(k, "Host") {
req.Host = v
Expand Down

0 comments on commit 7c3e2fd

Please sign in to comment.