From 4dacdc31f69f6917c334aae4cd645005d1e85845 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Fri, 9 Jan 2026 18:14:45 +0200 Subject: [PATCH] Fix to prevents NAT from dropping idle connections https://forum.virtualmin.com/t/problem-with-backup-of-large-virtual-servers-to-a-remote-webmin-server/136186/46 --- web-lib-funcs.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 4d1cb8aa6..8f05648ac 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -8542,8 +8542,19 @@ else { open(FILE, "<".$localfile) || return &$main::remote_error_handler("Failed to open $localfile : $!"); my $bs = &get_buffer_size(); + my $last_ping = time(); + my $ping_every = int(($gconfig{'rpc_timeout'} || 60) / 2); + $ping_every = 30 if ($ping_every < 30); while(read(FILE, $got, $bs) > 0) { print TWRITE $got; + if (time() - $last_ping >= $ping_every) { + eval { + local $main::remote_error_handler = + sub { return undef; }; + &remote_rpc_call($host, { 'action' => 'ping' }); + }; + $last_ping = time(); + } } close(FILE); shutdown(TWRITE, 1); @@ -8587,8 +8598,19 @@ else { open(FILE, ">$localfile") || return &$main::remote_error_handler("Failed to open $localfile : $!"); my $bs = &get_buffer_size(); + my $last_ping = time(); + my $ping_every = int(($gconfig{'rpc_timeout'} || 60) / 2); + $ping_every = 30 if ($ping_every < 30); while(read(TREAD, $got, $bs) > 0) { print FILE $got; + if (time() - $last_ping >= $ping_every) { + eval { + local $main::remote_error_handler = + sub { return undef; }; + &remote_rpc_call($host, { 'action' => 'ping' }); + }; + $last_ping = time(); + } } close(FILE); close(TREAD);