Skip to content

Commit

Permalink
impr(S3UTILS-181): Close all connections on server exit to prevent hang
Browse files Browse the repository at this point in the history
  • Loading branch information
tmacro committed Nov 18, 2024
1 parent 78a7a3e commit 475002d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion service-level-sidecar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@ function setupSignalHandlers(cleanUpFunc) {
startServer(server => {
log.info(`server listening on ${env.host}:${env.port}`);

const sockets = new Set();
server.on('connection', socket => {
sockets.add(socket);
socket.once('close', () => sockets.delete(socket));
});

if (env.tls.enabled) {
log.info('tls enabled', { apiServer: true, vault: env.vaultTls, bucketd: env.bucketdTls });
}

const cleanup = jsutil.once(() => {
log.info('server exiting');
server.close();
server.close(() => {
sockets.forEach(socket => socket.destroy());
log.info('server closed');
process.exit(0);
});
});

setupSignalHandlers(cleanup);
Expand Down

0 comments on commit 475002d

Please sign in to comment.