Skip to content

OR condition in radacct triggers silently discards one-sided usage deltas #137

Description

@maulanaady

Trigger logic: delta_input <= 0 OR delta_output <= 0 drops valid deltas

File: cake4/rd_cake/setup/db/8.090_add_radacct_triggers.sql
Triggers: manage_user_stats_after_insert (line 73–75), manage_user_stats_after_update (line 211–213)

Both triggers reject the row if either delta is non-positive:

IF delta_input <= 0 OR delta_output <= 0 THEN
    LEAVE proc;
END IF;

Issue: if only one direction increased since the last recorded bucket (e.g. input grew but output didn't move on this particular INSERT/UPDATE), the entire row — including the legitimate delta — is discarded. Nothing gets written to user_stats for that tick.

Example:

  • Previous cumulative totals in user_stats: acctinputoctets=1000, acctoutputoctets=500
  • New radacct row: acctinputoctets=1500, acctoutputoctets=500
  • delta_input=500, delta_output=0
  • Condition is true (delta_output <= 0) → LEAVE proc → the 500-byte input delta is silently dropped and never recorded anywhere.

Over time this causes SUM(acctinputoctets) / SUM(acctoutputoctets) in user_stats to drift from the true cumulative counters in radacct, especially at session close where one counter often stalls on the final packet.

Question: Is the OR intentional (e.g. to only record "complete" bidirectional traffic ticks), or should this be AND so a row is only skipped when neither direction moved?

If it's a bug, happy to submit a PR changing the condition to:

IF delta_input <= 0 AND delta_output <= 0 THEN
    LEAVE proc;
END IF;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions