1

I am trying to increase the write buffers of my http2 client, but it is not working.

I am setting it like below (at client side):

    httpTransport := &http.Transport {
       WriteBufferSize: 83000000,
       ReadBufferSize: 83000000,
   }
   http2Transport, err := http2.ConfigureTransports(httpTransport)
   if err != nil {
       return nil, fmt.Errorf("Failed to ConfigureTransports, %v", err)
   }

   http2Transport.AllowHTTP = true // So http2.Transport doesn't complain the URL scheme isn't 'https'
   http2Transport.TLSClientConfig = tlsCfg
   http2Transport.DialTLS = dialTls

   conn = &Client{
                   Client: &http.Client{
                       Transport: http2Transport,
                       Timeout: timeout,
                   },
                 }

I am using 'http2.Transport' (returned by http2.ConfigureTransports) to use http2 protocol.

But, with this change, the connection are not coming up, giving below error: http2: no cached connection was available

Please suggest if I am doing something wrong, or any other information required (to understand the problem/situation better). I want to increase the outgoing buffers of http2 client.

Complete problem is reported here: https://github.com/golang/go/issues/61545

I tried as mentioned above, and I was expecting http2 client side outgoing buffer to get increased (to improve through put), but with WriteBufferSize & ReadBufferSize change, even connects are not coming up. Please suggest a sample working code to increase outgoing bufferrs for http2 client.

Singh
  • 11
  • 1

1 Answers1

0

The error message indicates that there is no cached connection available in the HTTP/2 transport, and this might be due to the fact that you are setting the http2Transport.AllowHTTP field to true. When AllowHTTP is set to true, the HTTP/2 transport allows the use of HTTP/2 over plaintext (HTTP) instead of encrypted (HTTPS). However, HTTP/2 connection sharing (caching) requires HTTPS, and enabling AllowHTTP could be causing the cached connections not to work.

To fix this issue, you can set AllowHTTP to false to ensure that only HTTPS connections are used

Prashant Luhar
  • 299
  • 5
  • 19
  • Thanks. My code with flag 'AllowHTTP=true' is working fine with both - 'https' and 'http'; and I need both options (as a requirement). I just added WriteBufferSize, ReadBufferSize, resulting in problem mentioned in description. Do you think to increase write buffer size, I need to change 'AllowHTTP'? Is there any other way to increase write buffer size, without changing 'AllowHTTP'? – Singh Jul 24 '23 at 07:56
  • Ummm in such case using very large buffer sizes can lead to increased memory consumption, and it might cause the HTTP/2 implementation to behave differently or encounter issues with connection caching. In some cases, it might even exceed system limitations. Can try reducing the buffer size to a more reasonable value like 65536 = 64 KB – Prashant Luhar Jul 24 '23 at 09:00