mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #5909] [Feature]: Set different values of GOMEMLIMIT for xui and xray #4094
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#4094
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 @ilya-practicum on GitHub (Jul 12, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5909
Is your feature request related to a problem?
You cannot set different values of GOMEMLIMIT for x-ui and xray processes since GOMEMLIMIT overwrite XUI_MEMORY_LIMIT parameter.
Describe the solution you'd like
If both parameters set - XUI_MEMORY_LIMIT and GOMEMLIMIT, then first one will be applied to x-ui and second one to the xray. You will be able to set soft limits to two processes independently.
Alternatives you've considered
No response
Concrete use case
No response
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
No response
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Jul 12, 2026):
Confirmed: this is the current implementation's intended behavior, not a bug, and the split you're asking for is technically feasible without a new env var.
Two separate things are going on:
GOMEMLIMITintentionally wins overXUI_MEMORY_LIMITfor x-ui today. Ininternal/util/sys/memlimit.go,applyMemoryLimit()checksGOMEMLIMITfirst and returns immediately if it's set, without ever looking atXUI_MEMORY_LIMIT(lines 56-59);XUI_MEMORY_LIMITis only applied viadebug.SetMemoryLimit()whenGOMEMLIMITis unset (lines 61-67). This matches the documented precedence in.env.exampleanddocs/content/docs/en/reference/env-vars.mdx("takes precedence over above").GOMEMLIMITalso reaches the xray-core child process, independently of x-ui's own code.GOMEMLIMITis a native Go runtime variable: any Go binary that sees it in its environment applies it automatically beforemain()runs. Xray-core is itself a Go program (github.com/xtls/xray-core, pinned ingo.mod), andinternal/xray/process.go'sStart()(line 533) launches it viaexec.CommandContext(GetBinaryPath(), "-c", configPath)without ever settingcmd.Env. With a nilEnv, Go'sos/execmakes the child inherit the parent's full environment, so aGOMEMLIMITset for x-ui is passed straight through to xray-core, whose own runtime applies it on its own. So the "overwrite" you're seeing is really two independent Go runtimes reading the same shared variable, not 3x-ui code overwriting one flag with the other.Your proposed split is achievable: Go allows overriding an env-derived limit at runtime, not just at startup -
debug.SetMemoryLimit()can be called at any point to replace whateverGOMEMLIMITset initially, for that process only.applyMemoryLimit()could be changed to always applyXUI_MEMORY_LIMIT(when explicitly set) to the x-ui process viadebug.SetMemoryLimit(), regardless of whetherGOMEMLIMITis also present in the environment.GOMEMLIMITwould keep flowing to the xray-core child unchanged (no change needed inprocess.go), so it would still set xray's own soft limit independently. That gives exactly the outcome you described -XUI_MEMORY_LIMITfor x-ui,GOMEMLIMITfor xray, both effective at once - but it would flip today's documented precedence for the case where both are set, which is a user-visible behavior change worth a release note if implemented.Already labeled
enhancementcorrectly; no relabeling needed. @MHSanaei for a decision on prioritization and whether flipping the precedence (vs. introducing a separate xray-specific variable) is the preferred design.This reply was generated automatically by an AI assistant. A maintainer may follow up.