Skip to content

Commit

Permalink
Fix connection drops
Browse files Browse the repository at this point in the history
- Remove default connection timeout - nodejs/node#27558.
- Add client error listener.
  • Loading branch information
JeremyTCD committed Dec 6, 2019
1 parent 2cd5d66 commit ce7ded4
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/NodeJS/Javascript/Servers/OutOfProcess/Http/HttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ patchLStat();
// Set by NodeJSProcessFactory
let projectDir = process.cwd();

// Create server
const server = http.createServer(serverOnRequestListener);

// In Node.js 13+ this is the new default, however for earlier versions it is 120 seconds
server.setTimeout(0);

// If a connection drops we want as much information as possible
server.on('clientError', serverOnClientError);

// Start server
const server = http.createServer((req, res) => {
server.listen(parseInt(args.port), 'localhost', serverOnListeningListener);

function serverOnRequestListener(req, res) {
let bodyChunks = [];
req.
on('data', chunk => bodyChunks.push(chunk)).
Expand Down Expand Up @@ -158,12 +169,24 @@ const server = http.createServer((req, res) => {
respondWithError(res, error);
}
});
}).listen(parseInt(args.port), 'localhost', function () {
}

function serverOnClientError(error: Error, socket: stream.Duplex) {
let errorString = error.toString();
let httpResponseMessage = `HTTP/1.1 400 Bad Request\r
Content-Length: ${Buffer.byteLength(errorString, 'utf8')}
Content-Type: text/html\r
\r
${errorString}`;
socket.end(httpResponseMessage);
}

function serverOnListeningListener() {
// Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on
// and that we are ready to process invocations.
let info = server.address() as AddressInfo;
console.log(`[Jering.Javascript.NodeJS: Listening on IP - ${info.address} Port - ${info.port}]`);
});
}

function getTempIdentifier(invocationRequest: InvocationRequest): string {
if (invocationRequest.newCacheIdentifier == null) {
Expand Down

0 comments on commit ce7ded4

Please sign in to comment.