Hi,
Here is where system's TCP_KEEPIDLE default value is hard overridden for some reason:
|
// 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.
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
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):
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_intvlkernel parameter.