Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/engine.io/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ export interface ServerOptions {
* @default false
*/
allowEIO3?: boolean;
/**
* the maximum number of simultaneous connections. Any connection attempt above this threshold will be rejected.
* @default Infinity
*/
maxConnections?: number;
}

/**
Expand Down Expand Up @@ -454,6 +459,26 @@ export abstract class BaseServer extends EventEmitter {
return;
}

if (
this.opts.maxConnections != null &&
this.clientsCount >= this.opts.maxConnections
) {
debug(
"too many connections (maxConnections=%d)",
this.opts.maxConnections,
);
this.emit("connection_error", {
req,
code: Server.errors.FORBIDDEN,
message: Server.errorMessages[Server.errors.FORBIDDEN],
context: {
name: "CONNECTION_LIMIT_EXCEEDED",
},
});
closeConnection(Server.errors.FORBIDDEN);
return;
}

let id;
try {
id = await this.generateId(req);
Expand Down