mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(api): cleaner exits before respawn (#66135)
This commit is contained in:
committed by
GitHub
parent
b5e3a94693
commit
a391dc0664
+6
-1
@@ -41,6 +41,7 @@ import {
|
|||||||
FCC_ENABLE_SWAGGER_UI,
|
FCC_ENABLE_SWAGGER_UI,
|
||||||
FCC_ENABLE_SHADOW_CAPTURE,
|
FCC_ENABLE_SHADOW_CAPTURE,
|
||||||
FCC_ENABLE_SENTRY_ROUTES,
|
FCC_ENABLE_SENTRY_ROUTES,
|
||||||
|
FREECODECAMP_NODE_ENV,
|
||||||
GROWTHBOOK_FASTIFY_API_HOST,
|
GROWTHBOOK_FASTIFY_API_HOST,
|
||||||
GROWTHBOOK_FASTIFY_CLIENT_KEY
|
GROWTHBOOK_FASTIFY_CLIENT_KEY
|
||||||
} from './utils/env.js';
|
} from './utils/env.js';
|
||||||
@@ -86,7 +87,11 @@ export const buildOptions: FastifyHttpOptions<
|
|||||||
loggerInstance: getLogger(),
|
loggerInstance: getLogger(),
|
||||||
genReqId: () => randomBytes(8).toString('hex'),
|
genReqId: () => randomBytes(8).toString('hex'),
|
||||||
// disabled so we can customise the request/response logging
|
// disabled so we can customise the request/response logging
|
||||||
disableRequestLogging: true
|
disableRequestLogging: true,
|
||||||
|
// destroy all connections on close to avoid EADDRINUSE
|
||||||
|
// on restart, in development. Leave default in production.
|
||||||
|
forceCloseConnections:
|
||||||
|
FREECODECAMP_NODE_ENV === 'production' ? ('idle' as const) : true
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+11
-4
@@ -8,8 +8,17 @@ const start = async () => {
|
|||||||
|
|
||||||
const stop = async (signal: NodeJS.Signals) => {
|
const stop = async (signal: NodeJS.Signals) => {
|
||||||
fastify.log.info(`Received ${signal}, shutting down.`);
|
fastify.log.info(`Received ${signal}, shutting down.`);
|
||||||
|
|
||||||
|
fastify.server.closeAllConnections();
|
||||||
|
await new Promise<void>(resolve => {
|
||||||
|
fastify.server.close(() => resolve());
|
||||||
|
});
|
||||||
|
|
||||||
|
// Yield one tick so libuv can finalize uv_close() on the TCP handle
|
||||||
|
// before pino's autoEnd blocks the event loop via Atomics.wait().
|
||||||
|
await new Promise<void>(resolve => setImmediate(resolve));
|
||||||
|
|
||||||
await fastify.close();
|
await fastify.close();
|
||||||
fastify.log.info('Shutdown complete');
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -17,9 +26,7 @@ const start = async () => {
|
|||||||
process.on('SIGTERM', signal => void stop(signal));
|
process.on('SIGTERM', signal => void stop(signal));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const port = Number(PORT);
|
await fastify.listen({ port: Number(PORT), host: HOST });
|
||||||
fastify.log.info(`Starting server on port ${port}`);
|
|
||||||
await fastify.listen({ port, host: HOST });
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
fastify.log.error(err);
|
fastify.log.error(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user