Skip to content

Commit fd0000e

Browse files
committed
add timeouts
1 parent cf49ddc commit fd0000e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

apps/browser-proxy/src/tcp-server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ tcpServer.on('connection', async (socket) => {
2626
connectionId: string
2727
} | null = null
2828

29+
// 5 minutes idle timeout for the tcp connection
30+
socket.setTimeout(1000 * 60 * 5)
31+
socket.on('timeout', () => {
32+
debug('tcp connection timeout')
33+
socket.end()
34+
})
35+
2936
debug('new tcp connection')
3037

3138
const connection = await fromNodeSocket(socket, {

apps/browser-proxy/src/websocket-server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ websocketServer.on('error', (error) => {
4848
websocketServer.on('connection', async (websocket, request) => {
4949
debug('websocket connection')
5050

51+
// 1 hour lifetime for the websocket connection
52+
const websocketConnectionTimeout = setTimeout(
53+
() => {
54+
debug('websocket connection timed out')
55+
websocket.close()
56+
},
57+
1000 * 60 * 60 * 1
58+
)
59+
5160
const host = request.headers.host
5261

5362
if (!host) {
@@ -101,6 +110,7 @@ websocketServer.on('connection', async (websocket, request) => {
101110
})
102111

103112
websocket.on('close', () => {
113+
clearTimeout(websocketConnectionTimeout)
104114
connectionManager.deleteWebsocket(databaseId)
105115
// TODO: have a way of ending a PostgresConnection
106116
logEvent(new DatabaseUnshared({ databaseId, userId: user.id }))

0 commit comments

Comments
 (0)