You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// In Node.js v13+ this is the default, however for earlier versions it is 120 seconds.
29
+
// The timeouts below are designed to manage network instability. Since we're using the HTTP protocol on a local machine, we can disable them
30
+
// to avoid their overhead and stability issues.
31
+
32
+
// By default, on older versions of Node.js, request handling times out after 120 seconds.
33
+
// This timeout is disabled by default on Node.js v13+.
34
+
// Becuase of the older versions, we explicitly disable it.
30
35
server.setTimeout(0);
31
36
37
+
// By default, a socket is destroyed if it receives no incoming data for 5 seconds: https://nodejs.org/api/http.html#http_server_keepalivetimeout.
38
+
// This is good practice when making external requests because DNS records may change: https://github.com/dotnet/runtime/issues/18348.
39
+
// Since we're using the HTTP protocol on a local machine, it's safe and more efficient to keep sockets alive indefinitely.
40
+
server.keepAliveTimeout=0;
41
+
42
+
// By default, a socket is destroyed if its incoming headers take longer than 60 seconds: https://nodejs.org/api/http.html#http_server_headerstimeout.
43
+
// In early versions of Node.js, even if setTimeout() was specified with a non-zero value, the server would wait indefinitely for headers.
44
+
// This timeout was added to deal with that issue. We specify setTimeout(0), so this timeout is of no use to us.
45
+
//
46
+
// Note that while 0 disables this timeout in node 12.17+, in earlier versions it causes requests to time out immediately, so set to 10 years.
47
+
server.headersTimeout=10*365*24*60*60*1000;
48
+
49
+
// Log timed out connections for debugging
50
+
server.on('timeout',serverOnTimeout);
51
+
32
52
// Send client error details to client for debugging
33
53
server.on('clientError',serverOnClientError);
34
54
@@ -182,6 +202,12 @@ function serverOnClientError(error: Error, socket: stream.Duplex) {
182
202
socket.end(httpResponseMessage);
183
203
}
184
204
205
+
// Send timeout details to client for debugging - this shouldn't fire but there have been various node http server timeout issues in the past.
206
+
// The socket won't actually get closed (the timeout function needs to do that manually).
207
+
functionserverOnTimeout(socket: Socket){
208
+
console.error(`Ignoring unexpected socket timeout for address ${socket.remoteAddress}, port ${socket.remotePort}`);
209
+
}
210
+
185
211
functionserverOnListeningListener(){
186
212
// Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on
0 commit comments