Repository: fatedier/frp (language: go)

Issue:
Documentation of frps.ini TCPKeepAlive/tcp_keepalive incorrect
### 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


Discussion / hints:
Have you tried set it to -1? I don't remember very clearly, but I should have tested this usage.
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
> 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
```
I found that the behavior of this action varies on different operating systems. It would be better to explicitly specify `SetKeepAlive(false)`.

Fix patch:
diff --git a/go.mod b/go.mod
index b42d8801d2e..9572d9523d4 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
 	github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
 	github.com/coreos/go-oidc/v3 v3.4.0
 	github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb
-	github.com/fatedier/golib v0.1.1-0.20230628070619-a1a0c648236a
+	github.com/fatedier/golib v0.1.1-0.20230717092310-8d13bff6d373
 	github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible
 	github.com/go-playground/validator/v10 v10.11.0
 	github.com/google/uuid v1.3.0
diff --git a/go.sum b/go.sum
index c259697ed5c..c1e754d1747 100644
--- a/go.sum
+++ b/go.sum
@@ -121,8 +121,8 @@ github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
 github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb h1:wCrNShQidLmvVWn/0PikGmpdP0vtQmnvyRg3ZBEhczw=
 github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb/go.mod h1:wx3gB6dbIfBRcucp94PI9Bt3I0F2c/MyNEWuhzpWiwk=
-github.com/fatedier/golib v0.1.1-0.20230628070619-a1a0c648236a h1:HiRTFdy3ary86Vi2nsoINy2/YgjDPQ+21j3ikwJSD2E=
-github.com/fatedier/golib v0.1.1-0.20230628070619-a1a0c648236a/go.mod h1:Wdn1pJ0dHB1lah6FPYwt4AO9NEmWI0OzW13dpzC9g4E=
+github.com/fatedier/golib v0.1.1-0.20230717092310-8d13bff6d373 h1:lprMgD5nOD9k2Af0T/al8nU31YvFkTyCtRapi4z2jbQ=
+github.com/fatedier/golib v0.1.1-0.20230717092310-8d13bff6d373/go.mod h1:Wdn1pJ0dHB1lah6FPYwt4AO9NEmWI0OzW13dpzC9g4E=
 github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible h1:ssXat9YXFvigNge/IkkZvFMn8yeYKFX+uI6wn2mLJ74=
 github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible/go.mod h1:YpCOaxj7vvMThhIQ9AfTOPW2sfztQR5WDfs7AflSy4s=
 github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d h1:ynk1ra0RUqDWQfvFi5KtMiSobkVQ3cNc0ODb8CfIETo=


Test patch: