Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close socket timeouts without message #42456

Merged
merged 2 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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