Skip to content

Commit

Permalink
Fix is_connection_idle()
Browse files Browse the repository at this point in the history
Fix minor issue where is_connection_idle() returned incorrect results if there were not enough bandwidth usage samples (i.e. shortly after startup)
  • Loading branch information
tievolu authored Sep 30, 2022
1 parent fa5b05f commit 4dacb97
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions sqm-autorate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3020,21 +3020,23 @@ sub is_connection_idle {
foreach my $bw_usage_ref (@recent_bandwidth_usages) {
($start_time, $end_time, $bw_usage_ul, $bw_usage_dl, undef, undef) = @{$bw_usage_ref};

if (defined($start_time) && $end_time > $min_time) {
if ($bw_usage_ul >= $ul_bw_idle_threshold || $bw_usage_dl >= $dl_bw_idle_threshold) {
# This sample indicates a loaded connection
return 0;
if (defined($start_time)) { # Ensures this is a valid sample, not the first "dummy" sample
if ($end_time > $min_time) {
if ($bw_usage_ul >= $ul_bw_idle_threshold || $bw_usage_dl >= $dl_bw_idle_threshold) {
# This sample indicates a loaded connection
return 0;
}
} else {
# If we reach here we've searched back as far as $icmp_adaptive_idle_delay
# and found no samples that indicate a loaded connection
return 1;
}
} else {
# If we reach here we've searched back as far as $icmp_adaptive_idle_delay
# and found no samples that indicate a loaded connection
return 1;
}
}

# If we reach here we searched all of the bandwidth samples and none
# of them indicate a loaded connection
return 1;
# If we reach here we ran out of samples before we could determine whether the
# connection has been idle for $icmp_adaptive_idle_delay
return 0;
}

# Get the average bandwidth usage (kilobits/s) for both directions since the last latency summary
Expand Down

0 comments on commit 4dacb97

Please sign in to comment.