Skip to content

Commit

Permalink
close socket timeouts without message (#42456)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbudz committed Aug 9, 2019
1 parent a2dd2d0 commit da44c70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/core/server/http/http_tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions src/core/server/http/http_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit da44c70

Please sign in to comment.