fix: warn when connection limit drops a socket

Signed-off-by: hgshreyas <hgshreyas.cs24@bmsce.ac.in>
This commit is contained in:
hgshreyas authored and Diego Resendez committed 2026-08-30 12:55:20 -05:00
1 parent 4b04421ddd
commit 82e1678dea
4 files changed
+72 -2

No files matched your search

+2
View File
@@ -274,6 +274,7 @@ export function createApp(opts: {
const fetchOpts: HttpOptions = {
bus,
logger,
limits: opts.limits,
tls: opts.tls,
trustProxy: opts.trustProxy,
@@ -305,6 +306,7 @@ export function createApp(opts: {
server = createHttpServer(httpRoutes, wsRoutes, bus, meshControl, {
bus,
logger,
limits: opts.limits,
streams,
tls: opts.tls,
+15 -1
View File
@@ -53,7 +53,21 @@ export function createHttpServer(
? nodeHttps.createServer(opts.tls as https.ServerOptions, handler)
: nodeHttp.createServer(handler)) as unknown as http.Server;
const maxConnections = opts?.limits?.maxConnections ?? 1000;
if (maxConnections > 0) server.maxConnections = maxConnections;
if (maxConnections > 0) {
server.maxConnections = maxConnections;
let lastDropWarn = 0;
server.on('drop', ({ remoteAddress, remotePort }) => {
const now = Date.now();
if (now - lastDropWarn < 60_000) return;
lastDropWarn = now;
opts?.logger?.warn(
`maxConnections (${maxConnections}) reached \u2014 dropped connection from ${remoteAddress ?? 'unknown'}:${remotePort ?? 'unknown'}`,
{ maxConnections, remoteAddress, remotePort },
);
});
}
server.requestTimeout = opts?.limits?.requestTimeoutMs ?? 30_000;
server.headersTimeout = opts?.limits?.headersTimeoutMs ?? 10_000;
server.keepAliveTimeout = opts?.limits?.keepAliveTimeoutMs ?? 5_000;
+3
View File
@@ -5,6 +5,7 @@ import type { TlsOptions, SecurityOptions, CorsOptions } from '../security';
import type { WsRequest, WsSocket } from './ws-core';
import type { StaticResolver } from '../views';
import type { Bus } from '../bus';
import type { Logger } from '../logger';
/** Per-request and per-server resource ceilings applied by the server. */
export interface RequestLimits {
@@ -24,6 +25,8 @@ export interface HttpOptions {
* a separate channel for it.
*/
bus?: Bus;
/** Where this server writes diagnostics. Optional because `createHttpServer` takes no options at all in tests. */
logger?: Logger;
limits?: RequestLimits;
streams?: Set<() => void>;
tls?: TlsOptions;