@@ -25,7 +25,6 @@ import (
2525 "sync"
2626 "sync/atomic"
2727 "syscall"
28- "time"
2928
3029 "github.com/go-spring/log"
3130 "github.com/go-spring/spring-core/conf"
@@ -55,8 +54,6 @@ type App struct {
5554
5655 EnableJobs bool `value:"${spring.app.enable-jobs:=true}"`
5756 EnableServers bool `value:"${spring.app.enable-servers:=true}"`
58-
59- ShutDownTimeout time.Duration `value:"${spring.app.shutdown-timeout:=15s}"`
6057}
6158
6259// NewApp creates and initializes a new application instance.
@@ -137,7 +134,9 @@ func (app *App) Start() error {
137134 // runs all jobs
138135 if app .EnableJobs {
139136 for _ , job := range app .Jobs {
137+ app .wg .Add (1 )
140138 goutil .GoFunc (func () {
139+ defer app .wg .Done ()
141140 defer func () {
142141 if r := recover (); r != nil {
143142 app .ShutDown ()
@@ -188,29 +187,16 @@ func (app *App) Start() error {
188187// Stop gracefully shuts down the application, ensuring all servers and
189188// resources are properly closed.
190189func (app * App ) Stop () {
191- ctx , cancel := context .WithTimeout (context .Background (), app .ShutDownTimeout )
192- defer cancel ()
193-
194- waitChan := make (chan struct {})
195- goutil .GoFunc (func () {
196- for _ , svr := range app .Servers {
197- goutil .GoFunc (func () {
198- if err := svr .Shutdown (ctx ); err != nil {
199- log .Errorf (context .Background (), log .TagAppDef , "shutdown server failed: %v" , err )
200- }
201- })
202- }
203- app .wg .Wait ()
204- app .C .Close ()
205- waitChan <- struct {}{}
206- })
207-
208- select {
209- case <- waitChan :
210- log .Infof (context .Background (), log .TagAppDef , "shutdown complete" )
211- case <- ctx .Done ():
212- log .Infof (context .Background (), log .TagAppDef , "shutdown timeout" )
190+ for _ , svr := range app .Servers {
191+ goutil .GoFunc (func () {
192+ if err := svr .Shutdown (app .ctx ); err != nil {
193+ log .Errorf (context .Background (), log .TagAppDef , "shutdown server failed: %v" , err )
194+ }
195+ })
213196 }
197+ app .wg .Wait ()
198+ app .C .Close ()
199+ log .Infof (context .Background (), log .TagAppDef , "shutdown complete" )
214200}
215201
216202// Exiting returns a boolean indicating whether the application is exiting.
0 commit comments