Skip to content

Commit

Permalink
BLUE-231: Added socket timeout for open connections
Browse files Browse the repository at this point in the history
added keep alive config on connection
  • Loading branch information
aniketdivekar authored and mhanson-github committed Sep 4, 2024
1 parent 1f0d033 commit 30a0027
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ let port = config.port //8080
const chainId = config.chainId //8080

const extendedServer = http.createServer(app)
extendedServer.on('connection', (socket) => {
socket.setKeepAlive(true, 60000) // keep the connection to avoid unnecessary handshakes every time
socket.setTimeout(20000) // close connection after 20s of inactivity
socket.on('timeout', () => {
socket.end()
})
})

const wss = new WebSocket.Server({ server: extendedServer })

Expand Down

0 comments on commit 30a0027

Please sign in to comment.