Skip to content

Commit 601ebf4

Browse files
committed
fix: add more logs to the exit path
So we can understand better what cause the ending of the container
1 parent b7e23bd commit 601ebf4

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

src/server/server.ts

+40-10
Original file line numberDiff line numberDiff line change
@@ -154,28 +154,58 @@ if (EXPORT_DOCS) {
154154
} else if (GENERATE_TYPES) {
155155
console.log(await getTypeOutput())
156156
} else {
157-
const closeListeners = closeWithGrace(async ({ err }) => {
157+
const closeListeners = closeWithGrace(async ({ err, signal, manual }) => {
158158
if (err) {
159-
app.log.error(err)
159+
app.log.error({ err }, 'server closing with error')
160+
} else {
161+
app.log.error(
162+
{ err: new Error('Signal Received') },
163+
`${signal} signal received, server closing, close manual received: ${manual}`
164+
)
165+
}
166+
try {
167+
await app.close()
168+
} catch (err) {
169+
app.log.error({ err }, `Failed to close app`)
170+
throw err
171+
}
172+
try {
173+
await adminApp.close()
174+
} catch (err) {
175+
app.log.error({ err }, `Failed to close adminApp`)
176+
throw err
160177
}
161-
await app.close()
162-
await adminApp.close()
163178
})
164179
app.addHook('onClose', async () => {
165-
closeListeners.uninstall()
166-
await adminApp.close()
180+
try {
181+
closeListeners.uninstall()
182+
await adminApp.close()
183+
} catch (err) {
184+
app.log.error({ err }, `Failed to close adminApp in app onClose hook`)
185+
throw err
186+
}
167187
})
168188
adminApp.addHook('onClose', async () => {
169-
closeListeners.uninstall()
170-
await app.close()
189+
try {
190+
closeListeners.uninstall()
191+
await app.close()
192+
} catch (err) {
193+
app.log.error({ err }, `Failed to close app in adminApp onClose hook`)
194+
throw err
195+
}
171196
})
172197

173198
app.listen({ port: PG_META_PORT, host: PG_META_HOST }, (err) => {
174199
if (err) {
175-
app.log.error(err)
200+
app.log.error({ err }, 'Uncaught error in app, exit(1)')
176201
process.exit(1)
177202
}
178203
const adminPort = PG_META_PORT + 1
179-
adminApp.listen({ port: adminPort, host: PG_META_HOST })
204+
adminApp.listen({ port: adminPort, host: PG_META_HOST }, (err) => {
205+
if (err) {
206+
app.log.error({ err }, 'Uncaught error in adminApp, exit(1)')
207+
process.exit(1)
208+
}
209+
})
180210
})
181211
}

0 commit comments

Comments
 (0)