Open dfadev opened 1 year ago
It's not because packets get sent through the interface that the connection is working right? Or are you talking about receiving packets? What's your use case to monitor packets versus the current tcp dialing to 1.1.1.1:443?
It's for torrenting over links with high latency and lots of bandwidth management, like cellular. When there are a high number of peers the healthcheck begins to fail even though traffic is still being exchanged.
For a quick POC, I added this patch:
diff --git a/internal/healthcheck/health.go b/internal/healthcheck/health.go
index 2cd61426..8aa1b3ac 100644
--- a/internal/healthcheck/health.go
+++ b/internal/healthcheck/health.go
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net"
+ "os"
"time"
)
@@ -63,6 +64,10 @@ func (s *Server) runHealthcheckLoop(ctx context.Context, done chan<- struct{}) {
}
func (s *Server) healthCheck(ctx context.Context) (err error) {
+ if os.Getenv("DISABLE_HEALTH_TCP") == "true" {
+ return nil
+ }
+
// TODO use mullvad API if current provider is Mullvad
address, err := makeAddressToDial(s.config.TargetAddress)
And use this for the healthcheck in docker-compose:
test: ["CMD-SHELL", "packet_count=$$(cat /sys/class/net/tun0/statistics/rx_packets); sleep 2; new_packet_count=$$(cat /sys/class/net/tun0/statistics/rx_packets); if [ ! -z $$new_packet_count ] && [ $$new_packet_count -le $$packet_count ]; then exit 1; fi"]
With DISABLE_HEALTH_TCP set to true, and the custom healthcheck command set, I can push the connection to about 7500 peers without the VPN restarting at all. Without, the TCP check starts to recycle the VPN when the peer count reaches about 2500.
Restarting the VPN is not ideal because it takes time to handshake that many connections and unnecessary because some peer connections are still able to exchange traffic.
This will eventually be added thanks to #2411 which parses iptables results, and gets packets/bytes sent for each chain rule. We can use that to monitor traffic.
What's the feature 🧐
Make the healthcheck optionally monitor packet counts to determine if a connection is still healthy.
Extra information and references
On a saturated connection, the healthcheck can fail but the interface is still passing packets.