File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,21 +129,27 @@ const start = async () => {
129129
130130// Shut down the server
131131const shutdown = async ( server ) => {
132+ // Force exit after 5s if graceful shutdown hangs
133+ const forceTimeout = setTimeout ( ( ) => {
134+ console . error ( chalk . red ( 'Forced shutdown (timeout)' ) ) ;
135+ process . exit ( 1 ) ;
136+ } , 5000 ) ;
137+ forceTimeout . unref ( ) ;
138+
132139 try {
133- server . then ( async ( value ) => {
134- await mongooseService . disconnect ( ) ;
135- // add sequelize
136- value . http . close ( ( err ) => {
137- console . info ( chalk . yellow ( 'Server closed' ) ) ;
138- if ( err ) {
139- console . info ( chalk . red ( 'Error on server close.' , err ) ) ;
140- process . exitCode = 1 ;
141- }
142- process . exit ( ) ;
143- } ) ;
140+ const value = await server ;
141+ await mongooseService . disconnect ( ) ;
142+ value . http . close ( ( err ) => {
143+ console . info ( chalk . yellow ( 'Server closed' ) ) ;
144+ if ( err ) {
145+ console . info ( chalk . red ( 'Error on server close.' , err ) ) ;
146+ process . exitCode = 1 ;
147+ }
148+ process . exit ( ) ;
144149 } ) ;
145- } catch ( e ) {
146- throw new Error ( e ) ;
150+ } catch {
151+ // Server never started — just exit
152+ process . exit ( 1 ) ;
147153 }
148154} ;
149155
You can’t perform that action at this time.
0 commit comments