[PR #5494] [MERGED] fix(xray): write generated config file atomically #5902

Closed
opened 2026-11-02 04:04:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5494
Author: @n0ctal
Created: 6/22/2026
Status: ✅ Merged
Merged: 6/23/2026
Merged by: @MHSanaei

Base: main ← Head: pr-0014-atomic-xray-config


📝 Commits (1)

  • d1ef5ab fix(xray): write generated config atomically

📊 Changes

2 files changed (+96 additions, -1 deletions)

View changed files

📝 internal/xray/process.go (+49 -1)
📝 internal/xray/process_test.go (+47 -0)

📄 Description

The generated Xray config is written directly to its final path. A crash mid-write, or a concurrent reader (e.g. xray reloading) racing the write, can observe a truncated or partial config.

This writes to a temporary file in the same directory, fsyncs it, atomically renames it into place, and fsyncs the parent directory, with 0600 permissions. Readers therefore always see either the old or the complete new config, never a partial one.

Adds a test covering the atomic-write path.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5494 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 6/22/2026 **Status:** ✅ Merged **Merged:** 6/23/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `pr-0014-atomic-xray-config` --- ### 📝 Commits (1) - [`d1ef5ab`](https://github.com/MHSanaei/3x-ui/commit/d1ef5abe64f589c8dbf97c8604a84debc5327236) fix(xray): write generated config atomically ### 📊 Changes **2 files changed** (+96 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `internal/xray/process.go` (+49 -1) 📝 `internal/xray/process_test.go` (+47 -0) </details> ### 📄 Description The generated Xray config is written directly to its final path. A crash mid-write, or a concurrent reader (e.g. xray reloading) racing the write, can observe a truncated or partial config. This writes to a temporary file in the same directory, fsyncs it, atomically renames it into place, and fsyncs the parent directory, with 0600 permissions. Readers therefore always see either the old or the complete new config, never a partial one. Adds a test covering the atomic-write path. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:54 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5902
No description provided.