Skip to content

net: huge battery drain as TCP_KEEPIDLE is too low #79621

Description

@bam80

Hi,
Here is where system's TCP_KEEPIDLE default value is hard overridden for some reason:

go/src/net/dial.go

Lines 18 to 27 in e428359

// defaultTCPKeepAliveIdle is a default constant value for TCP_KEEPIDLE.
// See go.dev/issue/31510 for details.
defaultTCPKeepAliveIdle = 15 * time.Second
// defaultTCPKeepAliveInterval is a default constant value for TCP_KEEPINTVL.
// It is the same as defaultTCPKeepAliveIdle, see go.dev/issue/31510 for details.
defaultTCPKeepAliveInterval = 15 * time.Second
// defaultTCPKeepAliveCount is a default constant value for TCP_KEEPCNT.
defaultTCPKeepAliveCount = 9

As the value is too low, it creates a problem for many Go projects related with mobile connections, causing huge battery drain on many devices.

There is no workaround currently other than patch the suffered projects, one by one.

Here just a few reports I found, but more exist:
gotify/server#343 (comment):

There also exists a system default value (like net.ipv4.tcp_keepalive_time on Linux), but for some reasons, the Go developers decided to ignore it.

9seconds/mtg#526
v2ray/v2ray-core#2564
binwiederhier/ntfy#687
binwiederhier/ntfy#1195
https://discuss.grapheneos.org/d/16042-ntfy-high-battery-usage-on-cellular-but-not-wifi-pixel-8

Proposed solution:
Do not override TCP_KEEPIDLE by default and let system own the default value in net.ipv4.tcp_keepalive_intvl kernel parameter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions