Skip to content

Commit

Permalink
chore: adjust keep alive timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kayquecoelho committed Jul 6, 2023
1 parent ffa14f1 commit a1f6b0a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
26 changes: 20 additions & 6 deletions src/bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,32 @@ const database = require('../database')
const { ensureDatabaseIsConnected } = require('../functions/database')
const application = require('../server')
const { setupGracefulShutdown } = require('../server/shutdown')
const { makeLogger } = require('../lib/logger')

const { PORT = 3000 } = process.env

const startServer = app => app.listen(PORT)
const startServer = (app) => {
const server = app.listen(PORT)

server.keepAliveTimeout = 65 * 1000
server.headersTimeout = 66 * 1000

return server
}

const handleInitializationErrors = (err) => {
if (err instanceof DatabaseError) {
console.log(`Initialization failed with connection to database: ${err}`)
return process.exit(1)
}
const logger = makeLogger()
const isDatabaseError = err instanceof DatabaseError

logger.error({
message: 'Initialization failed',
metadata: {
error_message: err.message,
error_description: isDatabaseError ? 'Error on database connection' : 'Unknown error',
error_stack: err.stack ? err.stack.split('\n') : null,
},
})

console.log(`Unknown error: ${err}`)
return process.exit(1)
}

Expand Down
5 changes: 0 additions & 5 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const {
const app = express()
const allRoutesExceptHealthCheck = /^\/(?!_health_check(\/|$)).*$/i


app.use(bodyParser.json())

app.disable('x-powered-by')
Expand All @@ -40,8 +39,4 @@ app.get('/configurations/:external_id', showConfig)

app.all('*', defaultResourceHandler)

app.headersTimeout = 65 * 1000
app.keepAliveTimeout = 61 * 1000
app.timeout = 60 * 1000

module.exports = app

0 comments on commit a1f6b0a

Please sign in to comment.