[GH-ISSUE #3527] Documentation of frps.ini TCPKeepAlive/tcp_keepalive incorrect #2815

Closed
opened 2026-05-05 13:49:15 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @delaneyb on GitHub (Jul 12, 2023).
Original GitHub issue: https://github.com/fatedier/frp/issues/3527

Bug Description

Based on tracing the use of TCPKeepAlive through to handleConn in github.com/fatedier/golib/net/mux, it appears that the comparison actually performed to decide whether to call tcpConn.SetKeepAlivePeriod is if mux.keepAlive != 0, which contradicts the frps_full example, and the explanation in comments in server.go, which say that using a negative value for this setting in your config will disable tcp_keepalive probes.

According to pkg.go.dev, to explicitly disable keepalives on a Go TCPConn, we need to use SetKeepAlive(false)

frpc Version

0.48.0

frps Version

0.48.0

System Architecture

arm client/amd64 server

Configurations

frps.ini:

tcp_mux_keepalive_interval = 120
tcp_keepalive = -1

frpc.ini:
tcp_mux_keepalive_interval = 7200
dial_server_keepalive = 300

Logs

No response

Steps to reproduce

No response

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @delaneyb on GitHub (Jul 12, 2023). Original GitHub issue: https://github.com/fatedier/frp/issues/3527 ### Bug Description Based on tracing the use of `TCPKeepAlive` through to [`handleConn` in github.com/fatedier/golib/net/mux](https://github.com/fatedier/golib/blob/a1a0c648236af20e78b03094ad4f0716ae4788d7/net/mux/mux.go#L171), it appears that the comparison actually performed to decide whether to call `tcpConn.SetKeepAlivePeriod` is `if mux.keepAlive != 0`, which contradicts the [frps_full example](https://github.com/fatedier/frp/blob/8f105adbcac3b76a97a8e4744cfa31e85d4c51f1/conf/frps_full.ini#L141-L143), and the [explanation in comments in server.go](https://github.com/fatedier/frp/blob/8f105adbcac3b76a97a8e4744cfa31e85d4c51f1/pkg/config/server.go#L141-L143), which say that using a negative value for this setting in your config will disable tcp_keepalive probes. According to [pkg.go.dev](https://pkg.go.dev/net#TCPConn.SetKeepAlive), to explicitly disable keepalives on a Go TCPConn, we need to use `SetKeepAlive(false)` ### frpc Version 0.48.0 ### frps Version 0.48.0 ### System Architecture arm client/amd64 server ### Configurations frps.ini: tcp_mux_keepalive_interval = 120 tcp_keepalive = -1 frpc.ini: tcp_mux_keepalive_interval = 7200 dial_server_keepalive = 300 ### Logs _No response_ ### Steps to reproduce _No response_ ### Affected area - [X] Docs - [ ] Installation - [X] Performance and Scalability - [ ] Security - [X] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [ ] Others
gitea-mirror 2026-05-05 13:49:15 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@fatedier commented on GitHub (Jul 12, 2023):

Have you tried set it to -1? I don't remember very clearly, but I should have tested this usage.

<!-- gh-comment-id:1632526957 --> @fatedier commented on GitHub (Jul 12, 2023): Have you tried set it to -1? I don't remember very clearly, but I should have tested this usage.
Author
Owner

@delaneyb commented on GitHub (Jul 16, 2023):

Apologies for confusion, I have just tested with it set to -1 and 0 against netstat --timers. With a value of -1, it does in fact disable keepalives altogether. With a value of 0, it uses the go TCPConn default of 15 seconds

I must be misunderstanding what is getting called, or the syscall that I think is getting called when passed a negative duration just turns off keepalives for the socket

<!-- gh-comment-id:1636985742 --> @delaneyb commented on GitHub (Jul 16, 2023): Apologies for confusion, I have just tested with it set to -1 and 0 against `netstat --timers`. With a value of -1, it does in fact disable keepalives altogether. With a value of 0, it uses the [go TCPConn default of 15 seconds](https://cs.opensource.google/go/go/+/master:src/net/tcpsock.go;l=241?q=defaultTCPKeepAlive&sq=&ss=go%2Fgo) I must be misunderstanding what is getting called, or the [syscall that I think is getting called](https://cs.opensource.google/go/go/+/refs/heads/master:src/net/tcpsockopt_unix.go;l=18;drc=fe5af1532ab9c749d880c05e0ffe0e17bf874d7f) when passed a negative duration just turns off keepalives for the socket
Author
Owner

@delaneyb commented on GitHub (Jul 16, 2023):

Apologies for confusion, I have just tested with it set to -1 and 0 against netstat --timers. With a value of -1, it does in fact disable keepalives altogether. With a value of 0, it uses the go TCPConn default of 15 seconds

I must be misunderstanding what is getting called, or the syscall that I think is getting called when passed a negative duration just turns off keepalives for the socket

I was testing the above with frpc for the setting dial_server_keepalive running on Linux yb-4 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux

However, for frps on Linux frps 5.13.0-1023-gcp #28~20.04.1-Ubuntu SMP Wed Mar 30 03:51:07 UTC 2022 x86_64 Linux, whether tcp_keepalive is set to 0 or 1, it uses the Go default of 15s

Captures on both server and client:

image

frpc.ini

[common]
server_addr = xxxx
server_port = 7001

; Refer to Readme.md alongside frps.ini for info on these settings
heartbeat_interval = -1
tcp_mux_keepalive_interval = 50
; Negative => probes are disabled, 0 => default 15 seconds (https://github.com/fatedier/frp/issues/3527)
dial_server_keepalive = -1
tls_enable = false

log_level = debug

[ssh-xxxx]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 0
<!-- gh-comment-id:1637040058 --> @delaneyb commented on GitHub (Jul 16, 2023): > Apologies for confusion, I have just tested with it set to -1 and 0 against `netstat --timers`. With a value of -1, it does in fact disable keepalives altogether. With a value of 0, it uses the [go TCPConn default of 15 seconds](https://cs.opensource.google/go/go/+/master:src/net/tcpsock.go;l=241?q=defaultTCPKeepAlive&sq=&ss=go%2Fgo) > > I must be misunderstanding what is getting called, or the [syscall that I think is getting called](https://cs.opensource.google/go/go/+/refs/heads/master:src/net/tcpsockopt_unix.go;l=18;drc=fe5af1532ab9c749d880c05e0ffe0e17bf874d7f) when passed a negative duration just turns off keepalives for the socket I was testing the above with frpc for the setting `dial_server_keepalive` running on `Linux yb-4 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux` However, for frps on `Linux frps 5.13.0-1023-gcp #28~20.04.1-Ubuntu SMP Wed Mar 30 03:51:07 UTC 2022 x86_64 Linux`, whether `tcp_keepalive` is set to 0 or 1, it uses the [Go default of 15s](https://cs.opensource.google/go/go/+/master:src/net/tcpsock.go;l=241?q=defaultTCPKeepAlive&ss=go%2Fgo) Captures on both server and client: ![image](https://github.com/fatedier/frp/assets/18545667/30e26ff4-e58c-4f11-bed9-431c413c3dc9) frpc.ini ```ini [common] server_addr = xxxx server_port = 7001 ; Refer to Readme.md alongside frps.ini for info on these settings heartbeat_interval = -1 tcp_mux_keepalive_interval = 50 ; Negative => probes are disabled, 0 => default 15 seconds (https://github.com/fatedier/frp/issues/3527) dial_server_keepalive = -1 tls_enable = false log_level = debug [ssh-xxxx] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 0 ```
Author
Owner

@fatedier commented on GitHub (Jul 17, 2023):

I found that the behavior of this action varies on different operating systems. It would be better to explicitly specify SetKeepAlive(false).

<!-- gh-comment-id:1637665084 --> @fatedier commented on GitHub (Jul 17, 2023): I found that the behavior of this action varies on different operating systems. It would be better to explicitly specify `SetKeepAlive(false)`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#2815
No description provided.