Skip to content

Commit

Permalink
cta: limit shutdown timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Sep 11, 2023
1 parent 471bcbb commit bd57970
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/compose-tunnel-agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
MachineStatusCommand,
COMPOSE_TUNNEL_AGENT_PORT,
} from '@preevy/common'
import { inspect } from 'util'
import { createApp } from './src/api-server'
import { sshClient as createSshClient } from './src/ssh'
import { runMachineStatusCommand } from './src/machine-status'
import { envMetadata } from './src/metadata'
import { readAllFiles } from './src/files'
import { eventsClient as dockerEventsClient, filteredClient as dockerFilteredClient } from './src/docker'
import { inspect } from 'util'

const homeDir = process.env.HOME || '/root'
const dockerSocket = '/var/run/docker.sock'
Expand Down Expand Up @@ -143,12 +143,20 @@ const main = async () => {
return { end }
}

const SHUTDOWN_TIMEOUT = 5000

void main().then(
({ end }) => {
['SIGTERM', 'SIGINT'].forEach(signal => {
process.once(signal, async () => {
log.info(`shutting down on ${signal}`)
await end()
const endResult = await Promise.race([
end().then(() => true),
new Promise<void>(resolve => { setTimeout(resolve, SHUTDOWN_TIMEOUT) }),
])
if (!endResult) {
log.error(`timed out while waiting ${SHUTDOWN_TIMEOUT}ms for server to close, exiting`)
}
process.exit(0)
})
})
Expand Down

0 comments on commit bd57970

Please sign in to comment.