[PR #6686] [MERGED] Write config.json after a hot apply #6410

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6686
Author: @freeb5d
Created: 9/29/2026
Status: ✅ Merged
Merged: 10/2/2026
Merged by: @MHSanaei

Base: main ← Head: fix/hot-apply-write-config


📝 Commits (2)

  • 43e3d69 Write config.json after a hot apply
  • b97420e Test that a hot apply refreshes config.json

📊 Changes

4 files changed (+78 additions, -0 deletions)

View changed files

📝 internal/web/service/xray.go (+10 -0)
➕ internal/web/service/xray_hot_apply_persist_test.go (+25 -0)
📝 internal/xray/process.go (+16 -0)
➕ internal/xray/process_persist_test.go (+27 -0)

📄 Description

Fixes #6677

Problem

tryHotApply reconciles the running core through the gRPC API and only updates the in-memory snapshot (SetConfig). Process.Start() is the only place bin/config.json is written, so after a hot-applied save the file stays stale until the next cold start. Anything that reads it directly, such as the Telegram and Discord config backups, sees old rules. (Saved settings are not lost on restart: the config is always rebuilt from the database.)

Change

  • New Process.PersistConfig() writes the current snapshot with the same atomic write Start() uses.
  • tryHotApply calls it after SetConfig on both success paths. A write failure is logged as a warning and does not restart the running core.
  • Test: TestPersistConfigWritesCurrentSnapshot.

Testing

Not run: my environment has no C compiler for the SQLite driver. Files are gofmt-clean. Please rely on CI.


🔄 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/6686 **Author:** [@freeb5d](https://github.com/freeb5d) **Created:** 9/29/2026 **Status:** ✅ Merged **Merged:** 10/2/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/hot-apply-write-config` --- ### 📝 Commits (2) - [`43e3d69`](https://github.com/MHSanaei/3x-ui/commit/43e3d6992001aca21ebfaed36a31f0ab289ee71c) Write config.json after a hot apply - [`b97420e`](https://github.com/MHSanaei/3x-ui/commit/b97420e6d1712987a478fa54bded74b975c29583) Test that a hot apply refreshes config.json ### 📊 Changes **4 files changed** (+78 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/xray.go` (+10 -0) ➕ `internal/web/service/xray_hot_apply_persist_test.go` (+25 -0) 📝 `internal/xray/process.go` (+16 -0) ➕ `internal/xray/process_persist_test.go` (+27 -0) </details> ### 📄 Description Fixes #6677 ## Problem `tryHotApply` reconciles the running core through the gRPC API and only updates the in-memory snapshot (`SetConfig`). `Process.Start()` is the only place `bin/config.json` is written, so after a hot-applied save the file stays stale until the next cold start. Anything that reads it directly, such as the Telegram and Discord config backups, sees old rules. (Saved settings are not lost on restart: the config is always rebuilt from the database.) ## Change - New `Process.PersistConfig()` writes the current snapshot with the same atomic write `Start()` uses. - `tryHotApply` calls it after `SetConfig` on both success paths. A write failure is logged as a warning and does not restart the running core. - Test: `TestPersistConfigWritesCurrentSnapshot`. ## Testing Not run: my environment has no C compiler for the SQLite driver. Files are gofmt-clean. Please rely on CI. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:33 +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#6410
No description provided.