Skip to content

fix: refresh subscription history snapshots on MySQL and MariaDB - #888

Merged
x0sina merged 1 commit into
PasarGuard:pref-boostfrom
DrSaeedHub:fix/subscription-read-snapshot
Sep 9, 2026
Merged

x0sina merged 1 commit into
PasarGuard:pref-boostfrom
DrSaeedHub:fix/subscription-read-snapshot

Conversation

@DrSaeedHub

Copy link
Copy Markdown
Contributor

Summary

After a subscription request queues an update, MySQL and MariaDB subscription history endpoints can return an empty list even though the buffer has been flushed successfully. Authorization/user lookup has already established the request transaction's REPEATABLE READ snapshot, so it cannot see the flush committed by another session.

Read subscription history, agent counts, and chart statistics through a fresh session after flushing. This preserves the caller's transaction and pending changes, keeps pagination/count queries together, and also handles updates flushed before the read helper is called.

Follow-up to #886; fixes the two remaining failures in https://github.com/PasarGuard/panel/actions/runs/34364940294.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor / cleanup
  • Documentation
  • Tests / CI

Checklist

  • I tested the change locally or explained why it cannot be tested.
  • I added or updated tests for behavior changes.
  • I updated documentation, translations, or examples if needed. (Not needed.)
  • I checked database migrations when models or schema changed. (No schema changes; MySQL/MariaDB migration checks passed.)
  • I did not include secrets, tokens, private keys, or unrelated changes.

Testing

  • Reproduced both failing CI tests and six new snapshot regressions on MariaDB before the fix: 8 failed. The same cases passed after the fix.
  • Full suite on MySQL (Linux, Python 3.14): 601 passed, 2 skipped.
  • Full suite on MariaDB 10.6 (Linux, Python 3.14, NATS, two workers, all-in-one role): 601 passed, 2 skipped.
  • Full suite on SQLite (Windows, Python 3.14): 601 passed, 2 skipped.
  • Focused PostgreSQL 17 tests: 15 passed, covering six REPEATABLE READ cases, both affected API tests, and buffer regressions.
  • Alembic upgrades passed on all four engines; alembic check passed on MySQL and MariaDB.
  • Ruff lint/format checks and git diff --check passed.

The six regression cases cover history, agent counts, and time-bucketed stats with pending and already-flushed updates. They also verify that the caller's pending changes remain uncommitted.

Screenshots

Not applicable.

Notes for reviewers

Targets pref-boost. No changes to the global isolation level, schema, API response shape, or subscription write buffering. Subscription analytics use a separate database session for committed data; the request's original transaction remains untouched.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 746ffff5-43b9-49d5-b309-681d07e83b98

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@x0sina
x0sina merged commit 327afcc into PasarGuard:pref-boost Sep 9, 2026
10 checks passed
x0sina added a commit that referenced this pull request Sep 12, 2026
)

* feat(user): enhance user inbound tag retrieval and subscription update handling

- Improved the `inbounds` method in the User model to efficiently gather inbound tags from enabled groups.
- Updated user subscription update logic to queue updates for background processing, enhancing performance.
- Refactored user status change notifications to streamline the process and ensure accurate user state management.
- Introduced caching for usage coefficients to optimize node user statistics collection.
- Enhanced subscription generation with caching mechanisms for improved performance.

* fix: discard stale subscription updates and align FinalMask test (#886)

* fix: read flushed subscription updates from a fresh snapshot (#888)

* perf(nats): optimize user sync and bound queue processing (#892)

Reuse live key indexes, replay snapshots in bounded batches, and clear queues from cached keys and recent revisions. Bound bulk operations, safely compact old deletion markers, and preserve claim recovery across delayed notifications and reconnects.

Add concurrency, recovery, compaction, and idle-traffic regression coverage.

* test(hosts): match FinalMask noise fixture to Xray array packet

Keep the #889 payload ([1, 2, 255], no rand) so it agrees with the merged assertions after pref-boost picked up both that change and the older #886 sample.

* fix(cleanup): add timeout handling for node-sync key compaction and improve logging

- Introduced asyncio timeout for the compaction process to prevent indefinite blocking.
- Added a warning log for timeout occurrences to ensure visibility of potential issues.
- Updated Cache-Control header in subscription responses to "no-store" for better caching behavior.
- Refactored subscription update buffer to use a drain lock for concurrent flush operations, improving reliability and performance.

---------

Co-authored-by: DrSaeedHub <122322581+DrSaeedHub@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants