Avoid false rollover from float drift

pull/1088/head
Super User 2026-01-21 18:43:03 -05:00
parent 601ccb355d
commit 313071de71
1 changed files with 5 additions and 1 deletions

View File

@ -791,7 +791,11 @@ class WireguardConfiguration:
cur_total_receive = float(data_usage[i][1]) / (1024 ** 3)
cumulative_receive = cur_i['cumu_receive'] + total_receive
cumulative_sent = cur_i['cumu_sent'] + total_sent
if total_sent <= cur_total_sent and total_receive <= cur_total_receive:
# Allow minor floating-point drift to avoid false rollover.
epsilon_gb = 0.0005 # ~0.5 MB
sent_diff = cur_total_sent - total_sent
recv_diff = cur_total_receive - total_receive
if sent_diff >= -epsilon_gb and recv_diff >= -epsilon_gb:
total_sent = cur_total_sent
total_receive = cur_total_receive
else: