Bugfix: User can't change DNS Invaild Settings (#1042)

* Fix core restart panic on invalid DNS config

* Avoid nil instance race after core stop
This commit is contained in:
Seva
2026-03-07 17:34:33 +07:00
committed by GitHub
parent c70f0f97b3
commit a721c85955
2 changed files with 17 additions and 2 deletions
+16 -1
View File
@@ -2,6 +2,7 @@ package core
import (
"context"
"sync"
"github.com/alireza0/s-ui/logger"
@@ -28,6 +29,7 @@ var (
)
type Core struct {
mu sync.RWMutex
isRunning bool
instance *Box
}
@@ -46,10 +48,15 @@ func (c *Core) GetCtx() context.Context {
}
func (c *Core) GetInstance() *Box {
c.mu.RLock()
defer c.mu.RUnlock()
return c.instance
}
func (c *Core) Start(sbConfig []byte) error {
c.mu.Lock()
defer c.mu.Unlock()
var opt option.Options
err := opt.UnmarshalJSONContext(globalCtx, sbConfig)
if err != nil {
@@ -66,6 +73,7 @@ func (c *Core) Start(sbConfig []byte) error {
err = c.instance.Start()
if err != nil {
c.instance = nil
return err
}
@@ -81,13 +89,20 @@ func (c *Core) Start(sbConfig []byte) error {
}
func (c *Core) Stop() error {
c.mu.Lock()
defer c.mu.Unlock()
c.isRunning = false
if c.instance == nil {
return nil
}
return c.instance.Close()
err := c.instance.Close()
c.instance = nil
return err
}
func (c *Core) IsRunning() bool {
c.mu.RLock()
defer c.mu.RUnlock()
return c.isRunning
}