mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5375] [Bug]: shareAddrStrategy silently reverts to 'listen' when opening edit modal due to async node-loading race condition #3762
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#3762
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?
Originally created by @jshir700 on GitHub (Jun 16, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5375
Describe the bug
When an inbound has
shareAddrStrategyset to'node'(saved successfully via the API), opening the edit modal in the UI silently reverts it back to'listen'without any user interaction. Saving the modal without explicitly re-selecting "Node Address" (node) persists the wrong value to the backend.The root cause is a race condition in
InboundFormModal.tsxintroduced in commitc47a905(fix(inbound): offer node share-address strategy only when a node exists) and partially mitigated in commit90e6217(PR #5225,fix(inbound): preserve custom share strategy on edit). The partial fix only protects the'custom'value but does not resolve the underlying timing issue, so'node'is still silently overwritten on every modal open.How to reproduce the problem
Prerequisite: A multi-node setup with at least one online node (e.g., ARM2) and at least one local-only inbound (e.g., ARM1).
shareAddrStrategyto'node'for any inbound via the REST API:GET /panel/api/inbounds/listthat the API response contains"shareAddrStrategy": "node"for the updated inbound.node), matching the persisted API value.listen), even though the API still reportsshareAddrStrategy: "node".'listen'every time.GET /panel/api/inbounds/get/1that the backend value remains"shareAddrStrategy": "node"— the form has not saved the wrong value to the database, it only displays and will submit the wrong value.Important: This affects all inbounds, including those deployed to an online node (e.g., ARM2 with
nodeId=1). The race condition is not specific to "local" inbounds.Expected behavior
The UI form should faithfully display the persisted
shareAddrStrategyvalue from the API response when the edit modal opens. Specifically:shareAddrStrategy: "node", the dropdown should show "Node Address" (node).shareAddrStrategy: "listen", the dropdown should show "Listen Address" (listen).shareAddrStrategy: "custom", a text input forshareAddrshould appear.The
useEffectthat drops the'node'option should only fire after the node list has fully loaded (or failed to load), and should check the actual availability rather than the transient loading state. The effect should also not silently mutate the form value without user awareness.Actual behavior
The form silently overwrites
shareAddrStrategyfrom'node'to'listen'within milliseconds of the modal opening, due to auseEffectthat fires before the async node list API call completes.The specific code path:
rawInboundToFormValues(), which setsshareAddrStrategyto the API's value ('node'). ✅availableNodes(or the derivedselectableNodes) is an empty array — the fetch has not yet resolved.nodeShareOptionAvailableis computed asselectableNodes.length > 0 && isNodeEligible. SinceselectableNodesis[], this evaluates tofalse.useEffectat lines ~393–400 fires:currentis'node', the condition istrue→ value immediately set to'listen'. ❌selectableNodesis now populated (e.g., 2 nodes).nodeShareOptionAvailablebecomestrue. TheuseEffectre-fires due to the dependency change.form.getFieldValue('shareAddrStrategy')returns'listen'— it was just overwritten in step 4. The condition(current ?? 'node') === 'node'evaluates tofalse. The value is never restored. ❌This is a classic race condition between form initialization and async data loading. The
useEffectassumes that ifnodeShareOptionAvailableisfalseat the time it runs, there are genuinely no eligible nodes — but it cannot distinguish "no nodes exist" from "nodes have not loaded yet."Relevant code
File:
frontend/src/pages/inbounds/form/InboundFormModal.tsxLine 191 — eligibility flag:
Lines ~393-400 — the problematic effect:
Relevant commit history:
c47a905useEffectandnodeShareOptionAvailableflag; the original code unconditionally overwrote'node'with'listen'.90e6217(PR #5225)currentguard to preserve'custom'strategy on edit; the fix is incomplete because it does not address the underlying race condition.Suggested fix
The core problem is that
nodeShareOptionAvailableis not a reliable signal during the loading phase. TheuseEffectshould be gated on the node list having completed its initial load, regardless of whether the result is an empty list.Option A — Track loading state explicitly:
Option B — Use the query hook's loading state:
If
availableNodesis fetched via a hook that exposes anisLoadingorisPendingflag, gate the effect on that flag beingfalse:Option C — Check the actual resolved node count from the real API response:
Inject a short delay or a second-pass check in the effect to allow the async fetch to settle before making the fallback decision.
Relevant logs
Screenshots
No response
3x-ui version
3.3.1
Xray-core version
26.6.1
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04
Which parts of the panel are affected?
Frontend (UI / panel pages), Multi-node (sub-nodes)
Browser (only if it is a UI bug)
Microsoft Edge 132 (Chromium-based), also reproduced on Chrome 132
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@github-actions[bot] commented on GitHub (Jun 16, 2026):
The race condition is confirmed in the current source (v3.3.1). Here is the exact chain:
How the bug occurs
useNodesQueryinfrontend/src/api/queries/useNodesQuery.ts(line 36) initializesnodesasquery.data ?? []. Before the async/panel/api/nodes/listresponse arrives,nodesis an empty array.InboundsPage.tsx(line 104) only destructuresnodesfrom the hook:The hook's
fetchedflag (query.data \!== undefined || query.isError, line 79 ofuseNodesQuery.ts) is not forwarded to the modal.InboundFormModal.tsxderivesnodeShareOptionAvailablefrom the still-empty list:While the network request is in flight, this is
false.The
useEffectat lines 393–400 fires onopenbecomingtrue, seesnodeShareOptionAvailable === falseandcurrent === 'node', and overwrites the form value to'listen'before the node list arrives. When the node list does arrive, the same effect re-fires, but by thencurrentis already'listen', so no restoration occurs.The partial fix introduced in commit
90e6217(PR #5225, "fix(inbound): preserve custom share strategy on edit") changed the condition from an unconditional overwrite to:This correctly protected
'custom'because the condition only triggers whencurrentis'node'(orundefined). However, it still overwrites'node'itself, which is exactly the case reported here.Root cause distinction from #5224
Issue #5224 was specifically about
'custom'being overwritten; PR #5225 fixed that. The present issue concerns'node'being overwritten, which the same condition still allows. The underlying timing problem (effect fires before the async fetch resolves) was not addressed in that fix.Minimal fix
useNodesQueryalready exposes the information needed. The fix requires three localized changes:In
InboundsPage.tsx, also destructurefetched:Pass it to the modal (around line 652):
In
InboundFormModal.tsx, add the prop to the interface:Then gate the effect:
With this gate, the effect is a no-op while the fetch is pending and only enforces the fallback once the actual node list (including an empty one) has been confirmed by the API response.
Affected version: v3.3.1 (latest release). The
useNodesQuery.tsfetchedflag (query.data \!== undefined || query.isError) is available without any new API surface.This reply was generated automatically; a maintainer may follow up.