mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5442] [MERGED] fix(xray): guard log-writer race and bound handler gRPC deadlines #5884
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#5884
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/5442
Author: @n0ctal
Created: 6/19/2026
Status: ✅ Merged
Merged: 6/20/2026
Merged by: @MHSanaei
Base:
main← Head:pr-h09h11-xray-hardening📝 Commits (3)
b906689perf(xray): compile log/traffic regexps once at package scopede772d8fix(xray): guard LogWriter.lastLine against the GetResult reader raceb10adb8fix(xray): bound handler gRPC calls with a deadline📊 Changes
4 files changed (+99 additions, -17 deletions)
View changed files
📝
internal/xray/api.go(+30 -6)📝
internal/xray/log_writer.go(+30 -9)➕
internal/xray/log_writer_race_test.go(+36 -0)📝
internal/xray/process.go(+3 -2)📄 Description
Summary
Two small, independent correctness fixes to the Xray gRPC/log internals: a data race on the
log writer's last line, and missing deadlines on handler gRPC calls.
Why
LogWriter.lastLinedata race.Writeis driven by the Xray process output goroutine,while
Process.GetResultreadslastLinefrom the caller's goroutine. The field isunsynchronized, so the concurrent read/write is a data race (
go test -race).AddInbound,DelInboundand theAddUser->AlterInboundcall usecontext.Background(). If the core connection hangs, the callerblocks indefinitely — especially bad while the process restart lock is held. The other
handler operations already use a 10s timeout; these three were missed.
Scope
log_writer.go: add anRWMutextoLogWriter, exposeLastLine(), and route every writethrough
setLastLine().process.go:GetResultnow reads the last line viaLastLine().api.go: addhandlerRPCTimeout(10s) and apply it (plus a nil-client guard) toAddInbound,DelInbound, and theAddUserAlterInboundcall.Validation
go build ./internal/xray/...andgo vet ./internal/xray/...are clean.go test -race -shuffle=on ./internal/xray/...passes, including the addedTestLogWriterLastLineConcurrent(concurrentWrite+LastLine).Risk
Low. Both changes are localized to the Xray internals; behavior is unchanged except that
concurrent access to
lastLineis serialized and the three handler RPCs are now bounded.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.