From da44c70cbbb00a5d5345974960b5212193a8049f Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Fri, 9 Aug 2019 08:15:08 -0500 Subject: [PATCH] close socket timeouts without message (#42456) --- src/core/server/http/http_tools.test.ts | 7 +++---- src/core/server/http/http_tools.ts | 6 +----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/core/server/http/http_tools.test.ts b/src/core/server/http/http_tools.test.ts index 40344ed2c7034..b23cf2c4fd70c 100644 --- a/src/core/server/http/http_tools.test.ts +++ b/src/core/server/http/http_tools.test.ts @@ -69,7 +69,7 @@ describe('timeouts', () => { const logger = loggingServiceMock.create(); const server = new HttpServer(logger, 'foo'); - test('returns 408 on timeout error', async () => { + test('closes sockets on timeout', async () => { const router = new Router(''); router.get({ path: '/a', validate: false }, async (req, res) => { await new Promise(resolve => setTimeout(resolve, 2000)); @@ -87,9 +87,8 @@ describe('timeouts', () => { await server.start(); - await supertest(innerServer.listener) - .get('/a') - .expect(408); + expect(supertest(innerServer.listener).get('/a')).rejects.toThrow('socket hang up'); + await supertest(innerServer.listener) .get('/b') .expect(200); diff --git a/src/core/server/http/http_tools.ts b/src/core/server/http/http_tools.ts index 24c0264893d11..2953d5272ebe9 100644 --- a/src/core/server/http/http_tools.ts +++ b/src/core/server/http/http_tools.ts @@ -97,11 +97,7 @@ export function createServer(serverOptions: ServerOptions, listenerOptions: List server.listener.keepAliveTimeout = listenerOptions.keepaliveTimeout; server.listener.setTimeout(listenerOptions.socketTimeout); server.listener.on('timeout', socket => { - if (socket.writable) { - socket.end(Buffer.from('HTTP/1.1 408 Request Timeout\r\n\r\n', 'ascii')); - } else { - socket.destroy(); - } + socket.destroy(); }); server.listener.on('clientError', (err, socket) => { if (socket.writable) {