Repository navigation
fix(node): let lifecycle operations preempt user sync - #903
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
Walkthrough
ChangesNode sync lifecycle
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant NodeOperation
participant NodeManager
participant UserSyncTask
NodeOperation->>NodeManager: start user sync
NodeManager->>UserSyncTask: track sync task
NodeManager->>UserSyncTask: cancel on connection change or removal
UserSyncTask-->>NodeManager: lifecycle cancellation
NodeManager-->>NodeOperation: raise UserSyncPreemptedError
NodeOperation-->>NodeOperation: return HTTP 409 without node status update
Suggested reviewers: Merge Risk: 🔵 Low · up to A sync started during a node change or removal can briefly defeat preemption. The PR is mergeable with awareness of this bounded concurrency risk. Pre-merge checks |
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
…on-sync-lock # Conflicts: # app/node/__init__.py
3aef26a to
47ddab7
Compare
Cancel in-flight user syncs from update_node only when the connection
signature changed (and from remove_node as before). A name or usage
coefficient edit now waits for the per-node lock instead: bulk deliveries
release it between batches and continue on the replacement object, so
pending user deltas are not dropped. Once metadata-only edits stop
restarting the node, nothing else would re-send cancelled deltas.
Run sync_full in its own tracked task. Preemption then cancels only the
sync, never the caller (in single-process mode that is the admin's
POST /node/{id}/sync request), and the caller gets UserSyncPreemptedError,
which the node operation maps to a 409 without marking the node as
errored. Cancelling the caller still cancels the sync.
Log deliveries cancelled by a lifecycle change at debug level in
_update_users instead of dropping the CancelledError results silently.
- removal cancels a stuck per-user fallback delivery - an unchanged health-check reconnect keeps a running full or bulk sync, while a connection change cancels it - a name or usage coefficient edit waits for the batch in flight and the remaining batches reach the replacement object - a metadata edit waits for a running full sync - preempting sync_full raises UserSyncPreemptedError in the caller and cancelling the caller cancels the sync - the sync endpoint maps preemption to 409 without an error status
|
@coderabbitai review |
✅ Action performedReview finished.
|
Brings in PasarGuard#903 (lifecycle preemption of user syncs) and the rest of dev. Conflict in app/node/__init__.py: - update_node: keep PasarGuard#903's structure (early unchanged-signature return before the lock, preemption only on a connection change, re-check under the lock) and this branch's existing_signature read under the reader lock, which feeds remote_stop=existing_signature != signature. - keep this branch's _sync_user_batches helper and PasarGuard#903's _sync_users_to_node (node may be None, lock taken per batch, tracked for preemption); the shared-store branch from this side is already inside PasarGuard#903's version.
…e03754dec Checked with git ls-remote on 2026-10-11 14:49 UTC; every other forked repository, tag and release is unchanged since 02:55 UTC. - PasarGuard#617 (ef84f21) and the confirmation-dialog escaping (1c25036) are ported by design: the fork has 24bcbba and 0e08156 for the CORS credentials and the constant-time signature compare, and 9c3ae14 for the dialogs (escapeValue on, Trans instead of raw HTML). - The chart stylesheet escaping (a1d697b) and PasarGuard#859 (ba4a0ab, the device-limit race and the proxy_settings leak in /info and /raw) are queued security: yes; the fork has neither, so the gate is red on them until they are ported. - PasarGuard#950, PasarGuard#947, PasarGuard#857, PasarGuard#903, PasarGuard#908 and PasarGuard#996 are queued security: no until 2026-10-25, each with its reason. - Node PasarGuard#64 (e03754dec, WireGuard peers through Xray's UserManager, Go 1.27.1, unpinned pre-release Xray by default) is queued security: no until 2026-10-25; a port must pin the Xray tag. Against live upstream the panel gate now fails only on the 19 port-queue commits classified security: yes, and the node ledger only on f72ac0efacdb (security: yes).
* fix(node): let lifecycle operations preempt user sync
* fix(node): preempt user syncs only on connection changes or removal
Cancel in-flight user syncs from update_node only when the connection
signature changed (and from remove_node as before). A name or usage
coefficient edit now waits for the per-node lock instead: bulk deliveries
release it between batches and continue on the replacement object, so
pending user deltas are not dropped. Once metadata-only edits stop
restarting the node, nothing else would re-send cancelled deltas.
Run sync_full in its own tracked task. Preemption then cancels only the
sync, never the caller (in single-process mode that is the admin's
POST /node/{id}/sync request), and the caller gets UserSyncPreemptedError,
which the node operation maps to a 409 without marking the node as
errored. Cancelling the caller still cancels the sync.
Log deliveries cancelled by a lifecycle change at debug level in
_update_users instead of dropping the CancelledError results silently.
* test(node): cover lifecycle preemption of user syncs
- removal cancels a stuck per-user fallback delivery
- an unchanged health-check reconnect keeps a running full or bulk sync,
while a connection change cancels it
- a name or usage coefficient edit waits for the batch in flight and the
remaining batches reach the replacement object
- a metadata edit waits for a running full sync
- preempting sync_full raises UserSyncPreemptedError in the caller and
cancelling the caller cancels the sync
- the sync endpoint maps preemption to 409 without an error status
---------
Co-authored-by: T3ST3ST3R0N <[email protected]>
(cherry picked from commit 10ad680)
Summary
Node edits, disables, and removals could wait for many minutes when a bulk or full user sync held the per-node lock. A failed chunked sync made this especially visible because the bridge fallback retried users individually while lifecycle requests remained queued.
The PR changes only
app/node/__init__.py; it adds no documentation, test files, migrations, dependencies, or unrelated changes.Type of change
Checklist
Testing
python -m pytest tests/test_node_manager.py tests/test_node_manager_sync.py -q— 11 passed.python -m ruff check --no-fix app/node/__init__.py— passed.python -m ruff format --check app/node/__init__.py— passed.git diff --check— passed.Notes for reviewers
Cancellation is limited to user-sync tasks for the affected node and only happens for an actual configuration change or lifecycle removal. Automated reconnects with an unchanged connection signature and metadata continue to reuse the live node without disrupting synchronization.
Summary by CodeRabbit