Skip to content

fix: prevent stale subscription updates from breaking database CI - #886

Merged
x0sina merged 1 commit into
PasarGuard:pref-boostfrom
DrSaeedHub:fix/subscription-update-ci-34361432753
Sep 9, 2026
Merged

x0sina merged 1 commit into
PasarGuard:pref-boostfrom
DrSaeedHub:fix/subscription-update-ci-34361432753

Conversation

@DrSaeedHub

Copy link
Copy Markdown
Contributor

Summary

Buffered subscription updates for users deleted before a flush caused foreign-key violations, requeued the entire batch, and made subscription history and chart endpoints return HTTP 503. Flush bounded batches, discard records whose users no longer exist, and hold shared parent-row locks through insertion and commit to prevent concurrent deletion races. Valid records are preserved and database failures still requeue the batch.

Update the FinalMask API test to use the supported array packet format after the intentional removal of the rand noise type, with round-trip assertions for the packet and random length.

Fixes the failures in https://github.com/PasarGuard/panel/actions/runs/34361432753.

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; migration checks passed.)
  • I did not include secrets, tokens, private keys, or unrelated changes.

Testing

  • PostgreSQL 17 on Linux, Python 3.14: uv run pytest tests/ -q --tb=short — 595 passed, 2 skipped.
  • SQLite on Windows, Python 3.14: full suite — 593 passed, 2 skipped; subsequently expanded batch-boundary regression coverage passed in the targeted run below and the Linux full suite.
  • uv run --frozen pytest tests/test_sub_update_buffer.py -q --tb=short — 7 passed. Tests enable SQLite foreign keys and cover deleted-only and mixed batches, batch boundaries, and subsequent flushes. The new deleted-user cases reproduced the foreign-key failure before the fix.
  • alembic upgrade head and alembic check passed on SQLite and PostgreSQL.
  • Ruff lint and formatting checks passed for all changed files; git diff --check passed.
  • A Windows PostgreSQL full run passed all five tests that failed in the linked CI run, but reported 11 failures in time/usage reporting tests. The Linux PostgreSQL full run passed these tests as well.

Screenshots

Not applicable.

Notes for reviewers

Targets pref-boost and contains only commit 27c80594. No migrations or API contract changes. The buffer still writes outside the public subscription request path, and transient database errors retain the existing retry behavior.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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: 6ac43437-59b1-43b4-91ad-8203b846169a

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 ce739e2 into PasarGuard:pref-boost Sep 9, 2026
2 checks passed
x0sina added a commit that referenced this pull request Sep 12, 2026
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.
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 <[email protected]>
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