Skip to content

Commit 9167274

Browse files
committed
fix: prevent conflict in log config after sync users
1 parent c501ddd commit 9167274

5 files changed

Lines changed: 24 additions & 43 deletions

File tree

backend/xray/config.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,18 @@ func (c *Config) ToBytes() ([]byte, error) {
359359
}
360360
}
361361

362+
// Save Variables for next use
363+
aLog := c.LogConfig.AccessLog
364+
eLog := c.LogConfig.ErrorLog
365+
c.LogConfig.AccessLog = ""
366+
c.LogConfig.ErrorLog = ""
367+
362368
b, err := json.Marshal(c)
363369

370+
// Restore variables to prevent conflict on next run
371+
c.LogConfig.AccessLog = aLog
372+
c.LogConfig.ErrorLog = eLog
373+
364374
// Release all locks
365375
for _, i := range c.InboundConfigs {
366376
i.mu.RUnlock()
@@ -482,13 +492,14 @@ func (c *Config) checkPolicy() {
482492
}
483493
}
484494

485-
func (c *Config) RemoveLogFiles() (accessFile, errorFile string) {
486-
accessFile = c.LogConfig.AccessLog
487-
c.LogConfig.AccessLog = ""
488-
errorFile = c.LogConfig.ErrorLog
489-
c.LogConfig.ErrorLog = ""
495+
func (c *Config) GetLogFiles() (accessFile, errorFile string) {
496+
if c.LogConfig == nil {
497+
c.LogConfig = &conf.LogConfig{
498+
LogLevel: "info",
499+
}
500+
}
490501

491-
return accessFile, errorFile
502+
return c.LogConfig.AccessLog, c.LogConfig.ErrorLog
492503
}
493504

494505
func NewXRayConfig(config string, exclude []string) (*Config, error) {

backend/xray/core.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,7 @@ func (c *Core) Started() bool {
105105
}
106106

107107
func (c *Core) Start(xConfig *Config, debugMode bool) error {
108-
logConfig := xConfig.LogConfig
109-
if logConfig == nil {
110-
return errors.New("log config is empty")
111-
}
112-
113-
logLevel := logConfig.LogLevel
114-
if logLevel == "none" || logLevel == "error" {
115-
xConfig.LogConfig.LogLevel = "warning"
116-
}
117-
118-
accessFile, errorFile := xConfig.RemoveLogFiles()
108+
accessFile, errorFile := xConfig.GetLogFiles()
119109

120110
bytesConfig, err := xConfig.ToBytes()
121111
if debugMode {

backend/xray/jobs.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ func (x *Xray) extractError() error {
2929
}
3030

3131
func (x *Xray) checkXrayStatus(baseCtx context.Context) error {
32-
consecutiveFailures := 0
33-
maxFailures := 10 // Allow a few failures before restarting
34-
3532
for {
3633
select {
3734
case <-baseCtx.Done():
@@ -49,13 +46,8 @@ func (x *Xray) checkXrayStatus(baseCtx context.Context) error {
4946

5047
if err == nil {
5148
return nil
52-
} else {
53-
consecutiveFailures++
54-
if consecutiveFailures >= maxFailures {
55-
return x.extractError()
56-
}
5749
}
58-
time.Sleep(800 * time.Millisecond)
50+
time.Sleep(500 * time.Millisecond)
5951
}
6052
}
6153
}

controller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/pasarguard/node/tools"
1717
)
1818

19-
const NodeVersion = "0.2.5"
19+
const NodeVersion = "0.2.6"
2020

2121
type Service interface {
2222
Disconnect()

tools/sys.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func GetSystemStats() (*common.SystemStatsResponse, error) {
4949
// Loopback interface (lo) is excluded from the calculation.
5050
func getBandwidthSpeed() (uint64, uint64, error) {
5151
// 1) First snapshot with timestamp
52-
start := time.Now()
5352
first, err := net.IOCounters(true)
5453
if err != nil {
5554
return 0, 0, err
@@ -63,15 +62,8 @@ func getBandwidthSpeed() (uint64, uint64, error) {
6362
if err != nil {
6463
return 0, 0, err
6564
}
66-
end := time.Now()
6765

68-
// 4) Calculate actual elapsed time (not assumed 1 second)
69-
actualDuration := end.Sub(start).Seconds()
70-
if actualDuration == 0 {
71-
return 0, 0, nil // avoid division by zero
72-
}
73-
74-
// 5) Build a map from interface name → first snapshot
66+
// 4) Build a map from interface name → first snapshot
7567
// Skip loopback interface
7668
prev := make(map[string]net.IOCountersStat, len(first))
7769
for _, c := range first {
@@ -82,7 +74,7 @@ func getBandwidthSpeed() (uint64, uint64, error) {
8274
prev[c.Name] = c
8375
}
8476

85-
// 6) Compute deltas and sum across all interfaces
77+
// 5) Compute deltas and sum across all interfaces
8678
// Skip loopback interface
8779
var totalRxBytes, totalTxBytes uint64
8880
for _, c := range second {
@@ -96,10 +88,6 @@ func getBandwidthSpeed() (uint64, uint64, error) {
9688
}
9789
}
9890

99-
// 7) Convert bytes to bytes per second using ACTUAL measured time
100-
rxPerSecond := uint64(float64(totalRxBytes) / actualDuration)
101-
txPerSecond := uint64(float64(totalTxBytes) / actualDuration)
102-
103-
// 8) Return the calculated rates (bytes per second)
104-
return rxPerSecond, txPerSecond, nil
91+
// 6) Return the calculated rates (bytes per second)
92+
return totalRxBytes, totalTxBytes, nil
10593
}

0 commit comments

Comments
 (0)