Skip to content

net/http: missing HTTP KeepAlive timeout configuration #13998

Closed
@ghost

Description

Hi,

Currently it seems that it's only possible to enable or disable HTTP KeepAlive. The following code shows how to disable it:

client = &http.Client{
        Transport: &http.Transport{
                DisableKeepAlives: true,
        },
}

There does not seem to be configuration which allows you to specify a KeepAlive timeout, which would abandon idle connections that are inactive for longer than the timeout.

This is important as clients operating behind a Firewall / Proxy or targeting a server running behind a Firewall / Load Balancer might get their TCP connection closed after some period (e.g. 5 minutes) without getting informed. When this happens, Go fails the next HTTP call with read: connection reset by peer.

I faced such a scenario and checked Ruby to see how it would handle. It has multiple protections in place so that it does not error with read: connection reset by peer.

It is important to note that I am asking for an HTTP KeepAlive Timeout configuration. There is already a TCP KeepAlive Timeout configuration available in Go, which works just fine, but has a different purpose - to health-check a TCP connection by pushing regular ACK packages.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions