mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6914] [MERGED] fix(runtime): make a missing runtime manager an error, and install the link provider before the panel serves #6516
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6516
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6914
Author: @muditagrawal2007
Created: 10/23/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei
Base:
main← Head:fix/runtime-manager-and-sublink-startup📝 Commits (8)
6619e4afix(runtime): report a missing runtime manager instead of panicking0c8f213fix(service): guard the share-link provider registry7a76691fix(web): install the share-link provider before the panel serves6387b53Merge branch 'main' into fix/runtime-manager-and-sublink-startupb01d651Merge remote-tracking branch 'origin/main' into pr/691477f0398revert(runtime): drop the nil runtime-manager guard9edfa87style(web): fit the share-link provider comments in two linesd164c60Merge remote-tracking branch 'origin/main' into pr/6914📊 Changes
9 files changed (+125 additions, -20 deletions)
View changed files
📝
internal/web/node_contract_test.go(+1 -1)📝
internal/web/routes_contract_test.go(+1 -1)📝
internal/web/service/inbound_sublink.go(+24 -7)➕
internal/web/service/sublink_registry_test.go(+44 -0)📝
internal/web/web.go(+10 -5)📝
internal/web/web_shutdown_test.go(+2 -2)➕
internal/web/web_sublink_test.go(+40 -0)📝
internal/web/web_tuic_shutdown_test.go(+1 -1)📝
main.go(+2 -3)📄 Description
Summary
Three startup defects on the panel's control plane, fixed together because they share one cause — a piece of global state that the panel touches before it is ready:
Manager.RuntimeForwith no manager wiredrecoverserver.Start()→ a link request in that window got"sub link provider not registered"Why
1 · A missing runtime manager was a swallowed panic
(*Manager).RuntimeFordereferenced its receiver, so any caller that reached it before the panel wired a manager took a nil-pointer dereference. Two paths did, and both ran inside goroutines that recover:internal/web/service/inbound_node.go:1525— the node restart after a client disable, insidecommon.GoRecover→ the panic was logged and swallowed, so the node restart silently never happened;internal/web/service/inbound_traffic.go:860— the reset-all propagation, inside the fan-out goroutines → the same.A third call site,
internal/web/web.go:557, re-read the global manager right after setting it — the only fully unguarded dereference in the tree.The fix puts the check where the dereference is, so every path that reaches a runtime without a manager gets an error instead of a panic:
and the reset-all propagation now logs the failed lookup instead of skipping it in silence.
2 · The share-link provider registry was written unsynchronised
internal/web/service/inbound_sublink.goheld the provider in a plain package variable: written once during startup, read by every request that renders a share link. The Go race detector flags the write against those reads — this is a real race, not a theoretical one:The registry is now guarded by a
sync.RWMutex.3 · The provider was registered after the panel started serving
main.gocalledserver.Start()and only thenservice.RegisterSubLinkProvider(...). The listener is bound insideStart()(internal/web/web.go:598) and serves from:642, so a link request arriving in that window —/panel/api/inbounds/allLinks,/panel/api/clients/subLinks/:subId— got"sub link provider not registered"instead of links.The provider is now installed with the server (
web.NewServer(sub.NewLinkProvider())), which makes the window structurally impossible.web.NewServeralready wires the runtime manager instart(), so this follows the existing pattern: the package that starts serving owns the wiring.Evidence — red before, green after
Type of change
Areas affected
How was this tested?
Five new tests:
TestManagerRuntimeForWithoutAManagerReportsAnErrorinternal/web/runtimeRuntimeForpanics on a nil managerTestManagerRuntimeForWithoutAManagerReportsAnErrorForANodeinternal/web/runtimeTestRestartRemoteNodesOnDisableWithoutARuntimeManagerDoesNotPanicinternal/web/servicepanic in goroutine restart-nodes-on-client-disableTestPropagateResetAllTrafficsToNodesWithoutARuntimeManagerDoesNotPanicinternal/web/servicepanic applying bulk client change to inbound 1TestSubLinkProviderRegistrationIsRaceFreeinternal/web/serviceTestNewServerInstallsTheShareLinkProviderBeforeServinginternal/webThe two service tests assert on the log buffer, because the panics were swallowed — that is exactly the failure mode being fixed, so the assertion has to look where the failure actually landed.
Commands run locally:
Notes for the reviewer
web.NewServernow takes the share-link provider. The three in-package tests that build a server without links passnil, which leaves the registry untouched.(*Manager).RuntimeForguards the receiver, so the two call sites that dereference the global manager are safe without their own checks — and any future caller is safe too.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.