Skip to content

Commit 9309895

Browse files
swelljoeJoe Cooper
andauthored
Maybe reduce memory usage over time (#1731)
* Maybe reduce memory usage over time * Fix foreach over hash bug * Remove json_shared stuff --------- Co-authored-by: Joe Cooper <swelljoe@rocky-10-dev>
1 parent 626a9a6 commit 9309895

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

stats-lib-funcs.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ sub stats_network_proc
382382
my @rs;
383383
my $results = \%result;
384384
# Parse current data
385-
foreach (%$results) {
385+
foreach (keys %$results) {
386386
$rbytes += $results->{$_}->{'rbytes'};
387387
$tbytes += $results->{$_}->{'tbytes'};
388388
}
@@ -391,7 +391,7 @@ sub stats_network_proc
391391
select(undef, undef, undef, $wait_interval);
392392
$results = stats_network_proc(1);
393393
# Parse data after dalay
394-
foreach (%$results) {
394+
foreach (keys %$results) {
395395
$rbytes2 += $results->{$_}->{'rbytes'};
396396
$tbytes2 += $results->{$_}->{'tbytes'};
397397
}

stats.pl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use IO::Socket::INET;
1212
use Net::WebSocket::Server;
1313
use utf8;
14+
use Scalar::Util qw(weaken);
1415

1516
our ($current_theme, $json);
1617
require($ENV{'THEME_ROOT'} . "/stats-lib.pl");
@@ -143,9 +144,13 @@
143144
$serv->{'clients_connected'}++;
144145
alarm(0);
145146
# Set post-connect activity timeout
147+
my $wconn = $conn;
148+
weaken($wconn);
146149
$SIG{'ALRM'} = sub {
147-
error_stderr("WebSocket connection $conn->{'port'} is closed due to inactivity");
148-
$conn->disconnect();
150+
if ($wconn) {
151+
error_stderr("WebSocket connection $wconn->{'port'} is closed due to inactivity");
152+
$wconn->disconnect();
153+
}
149154
};
150155
alarm(30);
151156
# Set maximum send size

0 commit comments

Comments
 (0)