From 34f7c6755b0d77e5f5493db57c37d52a02b85546 Mon Sep 17 00:00:00 2001 From: mtraynham Date: Thu, 31 Aug 2017 12:54:56 -0400 Subject: [PATCH] fix(@angular/cli): Increase keepAliveTimeout for Webpack Dev Server --- packages/@angular/cli/tasks/serve.ts | 29 ++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/@angular/cli/tasks/serve.ts b/packages/@angular/cli/tasks/serve.ts index 232cc0dd37a0..55b49eb4a087 100644 --- a/packages/@angular/cli/tasks/serve.ts +++ b/packages/@angular/cli/tasks/serve.ts @@ -273,14 +273,27 @@ export default Task.extend({ } return new Promise((_resolve, reject) => { - server.listen(serveTaskOptions.port, serveTaskOptions.host, (err: any, _stats: any) => { - if (err) { - return reject(err); - } - if (serveTaskOptions.open) { - opn(serverAddress); - } - }); + const httpServer = server.listen( + serveTaskOptions.port, + serveTaskOptions.host, + (err: any, _stats: any) => { + if (err) { + return reject(err); + } + if (serveTaskOptions.open) { + opn(serverAddress); + } + }); + // Node 8.0 - 8.4 has a keepAliveTimeout bug which doesn't respect active connections. + // Connections will end after ~5 seconds (arbitrary), often not letting the full download + // of large pieces of content, such as a vendor javascript file. This results in browsers + // throwing a "net::ERR_CONTENT_LENGTH_MISMATCH" error. + // https://github.com/angular/angular-cli/issues/7197 + // https://github.com/nodejs/node/issues/13391 + // https://github.com/nodejs/node/commit/2cb6f2b281eb96a7abe16d58af6ebc9ce23d2e96 + if (/^v8.[0-4].\d+$/.test(process.version)) { + httpServer.keepAliveTimeout = 30000; // 30 seconds + } }) .catch((err: Error) => { if (err) {