Skip to content

Traffic: keep the last-read settings instead of the defaults when the settings cannot be read - #847

Merged
schmitch merged 1 commit into
mainfrom
claude/789-traffic-settings-read-failure
Nov 3, 2026
Merged

schmitch merged 1 commit into
mainfrom
claude/789-traffic-settings-read-failure

Conversation

@schmitch

@schmitch schmitch commented Nov 3, 2026

Copy link
Copy Markdown
Member

Fixes #789

Problem

When the traffic settings could not be read (PostgreSQL failing over, for example), the traffic worker used TrafficSettings::default() (client addresses on, default retention) in place of the stored settings:

  • spawn_worker started follow_settings from the defaults and kept them as long as reads failed. The minute flush wrote client addresses an administrator had turned off, and the hourly prune ran with the default retention, deleting days the configured retention keeps.
  • flush_on_shutdown flushed with read_settings(..).unwrap_or_default().
  • maxmind::update re-read the state with unwrap_or_default() and wrote it back without checking, which wiped the stored account_id.

Change

  • forge_traffic::Traffic keeps the settings last read (apply / applied). They are shared, so a restarted worker and the shutdown flush use them too. The admin settings PUT applies through the same method.
  • Worker (follow_settings now returns Option<TrafficSettings>): if a read fails, it keeps the settings applied before. Until one read has succeeded, the flush drops client addresses (flush_settings) and nothing is pruned (flush_and_prune).
  • Shutdown flush: it reads the settings once more, limited to 3 s of its 10 s. On failure it uses the applied settings, and without those it drops the addresses.
  • maxmind::update: it writes nothing over a state it cannot read back, and logs the outcome instead.
  • Changelog: docs/changes/2.2.0/789.fixed.md.

Tests

  • traffic::tests::addresses_turned_off_stay_off_when_the_settings_cannot_be_read: applied client_addresses: false, then failing reads; the worker keeps the settings, and the shutdown flush counts the request without an address.
  • traffic::tests::nothing_is_pruned_and_no_address_written_before_the_settings_are_read: with no read yet, an old day file is not pruned and no address is written; after a read, pruning runs.
  • tests/traffic.rs::a_download_recorded_over_a_state_it_cannot_read_keeps_the_account_id: a stored state that cannot be decoded is left as it is by update(). Against the old update() this test fails: account_id comes back null.

These all pass: cargo test -p forge-traffic (14 tests), cargo test -p forge-server --lib traffic (9) and cargo test -p forge-server --test traffic (4). cargo clippy -p forge-traffic -p forge-server --all-targets -- -D warnings, cargo fmt --check and cargo xtask changelog --check are clean.

No web UI change: the admin API is unchanged.


Generated by Claude Code

The worker seeded its settings with TrafficSettings::default() and the
shutdown flush used read_settings().unwrap_or_default(): with the
database unreachable, an instance recorded client addresses an
administrator had turned off and pruned with the default retention.

Traffic now keeps the settings last applied. The worker and the
shutdown flush fall back to them; before one read succeeded, the flush
drops client addresses and nothing is pruned. maxmind::update writes
nothing over a state it could not read again, which wiped account_id.

Fixes #789

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012e6DJbe2bmzbuPSvHMxpUd
@schmitch
schmitch added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit d4ec87d Nov 3, 2026
19 checks passed
@schmitch
schmitch deleted the claude/789-traffic-settings-read-failure branch November 3, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants