Repository navigation
Traffic: keep the last-read settings instead of the defaults when the settings cannot be read - #847
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_workerstartedfollow_settingsfrom 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_shutdownflushed withread_settings(..).unwrap_or_default().maxmind::updatere-read the state withunwrap_or_default()and wrote it back without checking, which wiped the storedaccount_id.Change
forge_traffic::Traffickeeps 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.follow_settingsnow returnsOption<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).maxmind::update: it writes nothing over a state it cannot read back, and logs the outcome instead.docs/changes/2.2.0/789.fixed.md.Tests
traffic::tests::addresses_turned_off_stay_off_when_the_settings_cannot_be_read: appliedclient_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 byupdate(). Against the oldupdate()this test fails:account_idcomes backnull.These all pass:
cargo test -p forge-traffic(14 tests),cargo test -p forge-server --lib traffic(9) andcargo test -p forge-server --test traffic(4).cargo clippy -p forge-traffic -p forge-server --all-targets -- -D warnings,cargo fmt --checkandcargo xtask changelog --checkare clean.No web UI change: the admin API is unchanged.
Generated by Claude Code