Refactor slow activities from nm-dispatcher script into separate listener service#680
Refactor slow activities from nm-dispatcher script into separate listener service#680lmagyar wants to merge 4 commits into
Conversation
|
Warning Review limit reached
More reviews will be available in 24 minutes and 40 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
WalkthroughThe dispatcher script refactors from direct synchronous subnet protection to queue-based enqueuing. New s6-overlay services ( ChangesSubnet Protection Async Queue Architecture
Sequence DiagramsequenceDiagram
participant NM as NetworkManager
participant Disp as Dispatcher Script
participant Queue as FIFO Queue
participant Listener as nm-dispatcher-listener
participant Routes as Route Protection
rect rgb(0, 100, 200, 0.5)
Note over NM,Routes: Old Flow (Synchronous, Blocking)
NM->>Disp: Interface up/down event
Disp->>Routes: protect-subnet-routes (blocks)
Routes->>Listener: Wait for Supervisor API
Listener-->>Routes: Timeout/Delay
Routes-->>Disp: Complete (slow)
Disp-->>NM: Dispatcher done (10+ min delay)
end
rect rgb(0, 150, 100, 0.5)
Note over NM,Routes: New Flow (Asynchronous, Non-blocking)
NM->>Disp: Interface up/down event
Disp->>Queue: Enqueue action (fast return)
Disp-->>NM: Dispatcher done (immediate)
Queue->>Listener: Read action from queue
Listener->>Routes: protect-subnet-routes (async)
Routes-->>Listener: Complete
Listener->>Listener: Update exit status
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tailscale/rootfs/etc/NetworkManager/dispatcher.d/protect-subnets`:
- Around line 17-21: Before writing to the listener queue, verify
NM_DISPATCHER_LISTENER_QUEUE exists and is a FIFO (use [ -p
"$NM_DISPATCHER_LISTENER_QUEUE" ]) and wait with a short timeout (e.g., loop up
to a few seconds) for it to appear as a FIFO; if it never becomes a FIFO, log
fatal and exit (same behavior as current error path). Do not create a regular
file by redirecting into a non-existent path; instead fail fast when the FIFO is
absent or wrong type. Use the existing variables DEVICE_IP_IFACE and
NM_DISPATCHER_ACTION for the payload and preserve the current exit behavior that
writes to /run/s6-linux-init-container-results/exitcode and calls halt if the
check/write fails.
In `@tailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher-listener/run`:
- Around line 22-25: The script must fail fast if mkfifo fails or the path is
not a FIFO: before executing "exec 4<>\"${NM_DISPATCHER_LISTENER_QUEUE}\"",
attempt to create the FIFO with mkfifo and then validate the path is a FIFO
using a POSIX test (e.g., [ -p "$NM_DISPATCHER_LISTENER_QUEUE" ]); if mkfifo
fails and the path is absent or exists but is not a FIFO, write an error and
exit non‑zero so the listener doesn't proceed to "exec 4<>" on a regular file.
Update the run script around the mkfifo/exec 4<> sequence to perform this
validation and early exit when the queue is not a proper FIFO.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 44d4ff22-5e51-49a1-9aa9-a5143aac6027
📒 Files selected for processing (19)
tailscale/rootfs/etc/NetworkManager/dispatcher.d/protect-subnetstailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/dependencies.d/local-networktailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/downtailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/finishtailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/runtailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/typetailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/uptailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher-listener/dependencies.d/init-protect-subnetstailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher-listener/finishtailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher-listener/runtailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher-listener/typetailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher/dependencies.d/nm-dispatcher-listenertailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher/finishtailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher/runtailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher/typetailscale/rootfs/etc/s6-overlay/s6-rc.d/protect-subnets/contents.d/init-protect-subnetstailscale/rootfs/etc/s6-overlay/s6-rc.d/protect-subnets/contents.d/nm-dispatchertailscale/rootfs/etc/s6-overlay/s6-rc.d/protect-subnets/contents.d/nm-dispatcher-listenertailscale/rootfs/etc/s6-overlay/s6-rc.d/protect-subnets/type
|
Looks quite neat, and I've tested it on my end, Tailscale no longer blocks Supervisor restart with this change (even with ✔️ LGTM! |
|
Thank you for the feedback! |
Proposed Changes
There is a plain linux pipe between the 2 services, each nm-dispatcher action is 1 line in it, then all the slow thing happen in the listener service sequentially - as currently, but returning to nm-dispatcher quickly.
Related Issues
fixes #678
closes #679
Summary by CodeRabbit