@@ -35,18 +35,18 @@ const (
3535
3636// CoreController represents a controller for managing Xray core instance lifecycle
3737type CoreController struct {
38- CallbackHandler CoreCallbackHandler
39- statsManager corestats.Manager
40- coreMutex sync.Mutex
41- coreInstance * core.Instance
42- IsRunning bool
38+ CallbackHandler CoreCallbackHandler // System callback handler
39+ statsManager corestats.Manager // Traffic statistics
40+ coreMutex sync.Mutex // Mutex for thread safety
41+ coreInstance * core.Instance // Xray core instance
42+ IsRunning bool // Service status flag
4343}
4444
4545// CoreCallbackHandler defines interface for receiving callbacks and notifications from the core service
4646type CoreCallbackHandler interface {
47- Startup () int
48- Shutdown () int
49- OnEmitStatus (int , string ) int
47+ Startup () int // Triggered on core start
48+ Shutdown () int // Triggered on core shutdown
49+ OnEmitStatus (int , string ) int // Status reporting
5050}
5151
5252// consoleLogWriter implements a log writer without datetime stamps
@@ -210,8 +210,10 @@ func CheckVersionX() string {
210210// doShutdown shuts down the Xray instance and cleans up resources
211211func (x * CoreController ) doShutdown () {
212212 if x .coreInstance != nil {
213- x .coreInstance .Close ()
214- x .coreInstance = nil
213+ if err := x .coreInstance .Close (); err != nil {
214+ log .Printf ("core shutdown error: %v" , err )
215+ }
216+ x .coreInstance = nil
215217 }
216218 x .IsRunning = false
217219 x .statsManager = nil
@@ -225,7 +227,6 @@ func (x *CoreController) doStartLoop(configContent string) error {
225227 return fmt .Errorf ("config error: %w" , err )
226228 }
227229
228- log .Println ("Creating new core instance" )
229230 x .coreInstance , err = core .New (config )
230231 if err != nil {
231232 return fmt .Errorf ("core init failed: %w" , err )
0 commit comments