Skip to content

Commit ce7ded4

Browse files
committed
Fix connection drops
- Remove default connection timeout - nodejs/node#27558. - Add client error listener.
1 parent 2cd5d66 commit ce7ded4

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/NodeJS/Javascript/Servers/OutOfProcess/Http/HttpServer.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,19 @@ patchLStat();
2323
// Set by NodeJSProcessFactory
2424
let projectDir = process.cwd();
2525

26+
// Create server
27+
const server = http.createServer(serverOnRequestListener);
28+
29+
// In Node.js 13+ this is the new default, however for earlier versions it is 120 seconds
30+
server.setTimeout(0);
31+
32+
// If a connection drops we want as much information as possible
33+
server.on('clientError', serverOnClientError);
34+
2635
// Start server
27-
const server = http.createServer((req, res) => {
36+
server.listen(parseInt(args.port), 'localhost', serverOnListeningListener);
37+
38+
function serverOnRequestListener(req, res) {
2839
let bodyChunks = [];
2940
req.
3041
on('data', chunk => bodyChunks.push(chunk)).
@@ -158,12 +169,24 @@ const server = http.createServer((req, res) => {
158169
respondWithError(res, error);
159170
}
160171
});
161-
}).listen(parseInt(args.port), 'localhost', function () {
172+
}
173+
174+
function serverOnClientError(error: Error, socket: stream.Duplex) {
175+
let errorString = error.toString();
176+
let httpResponseMessage = `HTTP/1.1 400 Bad Request\r
177+
Content-Length: ${Buffer.byteLength(errorString, 'utf8')}
178+
Content-Type: text/html\r
179+
\r
180+
${errorString}`;
181+
socket.end(httpResponseMessage);
182+
}
183+
184+
function serverOnListeningListener() {
162185
// Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on
163186
// and that we are ready to process invocations.
164187
let info = server.address() as AddressInfo;
165188
console.log(`[Jering.Javascript.NodeJS: Listening on IP - ${info.address} Port - ${info.port}]`);
166-
});
189+
}
167190

168191
function getTempIdentifier(invocationRequest: InvocationRequest): string {
169192
if (invocationRequest.newCacheIdentifier == null) {

0 commit comments

Comments
 (0)