Skip to content

Commit b709de0

Browse files
committed
add ocket_rate_limit_points_disconnect
1 parent f7b741b commit b709de0

7 files changed

Lines changed: 56 additions & 13 deletions

File tree

OpenFlow/src/Config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class Config {
5959
Config.api_rate_limit_duration = parseInt(Config.getEnv("api_rate_limit_duration", "1"));
6060
Config.socket_rate_limit = Config.parseBoolean(Config.getEnv("socket_rate_limit", "true"));
6161
Config.socket_rate_limit_points = parseInt(Config.getEnv("socket_rate_limit_points", "30"));
62+
Config.socket_rate_limit_points_disconnect = parseInt(Config.getEnv("socket_rate_limit_points_disconnect", "600"));
6263
Config.socket_rate_limit_duration = parseInt(Config.getEnv("socket_rate_limit_duration", "1"));
6364

6465
Config.client_heartbeat_timeout = parseInt(Config.getEnv("client_heartbeat_timeout", "60"));
@@ -173,6 +174,7 @@ export class Config {
173174
public static api_rate_limit_duration: number = parseInt(Config.getEnv("api_rate_limit_duration", "1"));
174175
public static socket_rate_limit: boolean = Config.parseBoolean(Config.getEnv("socket_rate_limit", "true"));
175176
public static socket_rate_limit_points: number = parseInt(Config.getEnv("socket_rate_limit_points", "30"));
177+
public static socket_rate_limit_points_disconnect: number = parseInt(Config.getEnv("socket_rate_limit_points_disconnect", "600"));
176178
public static socket_rate_limit_duration: number = parseInt(Config.getEnv("socket_rate_limit_duration", "1"));
177179

178180
public static client_heartbeat_timeout: number = parseInt(Config.getEnv("client_heartbeat_timeout", "60"));

OpenFlow/src/Messages/Message.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class Message {
7575
if (error.consumedPoints) {
7676
if (!NoderedUtil.IsNullUndefinded(WebSocketServer.websocket_rate_limit)) WebSocketServer.websocket_rate_limit.bind({ ...otel.defaultlabels, command: command }).add(1);
7777
if ((error.consumedPoints % 100) == 0) cli._logger.debug("[" + username + "/" + cli.clientagent + "/" + cli.id + "] SOCKET_RATE_LIMIT consumedPoints: " + error.consumedPoints + " remainingPoints: " + error.remainingPoints + " msBeforeNext: " + error.msBeforeNext);
78-
if (error.consumedPoints > (Config.socket_rate_limit_points * 2)) {
78+
if (error.consumedPoints >= Config.socket_rate_limit_points_disconnect) {
7979
cli._logger.debug("[" + username + "/" + cli.clientagent + "/" + cli.id + "] SOCKET_RATE_LIMIT: Disconnecing client ! consumedPoints: " + error.consumedPoints + " remainingPoints: " + error.remainingPoints + " msBeforeNext: " + error.msBeforeNext);
8080
cli.Close();
8181
}

OpenFlow/src/index.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,31 @@ process.on('warning', (warning) => {
284284
console.warn(warning.message); // Print the warning message
285285
console.warn(warning.stack); // Print the stack trace
286286
});
287-
function handle(signal) {
288-
console.log(`Received ${signal}`);
287+
// The signals we want to handle
288+
// NOTE: although it is tempting, the SIGKILL signal (9) cannot be intercepted and handled
289+
var signals = {
290+
'SIGHUP': 1,
291+
'SIGINT': 2,
292+
'SIGTERM': 15
293+
};
294+
function handle(signal, value) {
295+
console.trace(`process received a ${signal} signal with value ${value}`);
296+
try {
297+
server.close((err) => {
298+
console.log(`server stopped by ${signal} with value ${value}`);
299+
console.error(err);
300+
process.exit(128 + value);
301+
})
302+
} catch (error) {
303+
console.error(error);
304+
console.log(`server stopped by ${signal} with value ${value}`);
305+
process.exit(128 + value);
306+
}
289307
}
290-
process.on('SIGTERM', handle);
291-
process.on('SIGINT', handle);
308+
Object.keys(signals).forEach((signal) => process.on(signal, handle));
309+
310+
// process.on('SIGTERM', handle);
311+
// process.on('SIGINT', handle);
292312
// process.on('SIGUSR1', handle);
293313
// process.on('SIGPIPE', handle);
294314
// process.on('SIGHUP', handle);
@@ -330,11 +350,12 @@ const originalStderrWrite = process.stderr.write.bind(process.stderr);
330350
// write(str: string, encoding?: string, cb?: (err?: Error | null) => void): boolean;
331351

332352
// https://medium.com/kubernetes-tutorials/monitoring-your-kubernetes-deployments-with-prometheus-5665eda54045
353+
var server: http.Server = null;
333354
(async function (): Promise<void> {
334355
try {
335356
await initamqp();
336357
logger.info("VERSION: " + Config.version);
337-
const server: http.Server = await WebServer.configure(logger, Config.baseurl(), _otel);
358+
server = await WebServer.configure(logger, Config.baseurl(), _otel);
338359
if (GrafanaProxy != null) {
339360
const grafana = await GrafanaProxy.GrafanaProxy.configure(logger, WebServer.app, _otel);
340361
}

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/nodered",
3-
"version": "1.2.23",
3+
"version": "1.2.24",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

OpenFlowNodeRED/src/index.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,31 @@ process.on('warning', (warning) => {
7272
console.warn(warning.message); // Print the warning message
7373
console.warn(warning.stack); // Print the stack trace
7474
});
75-
function handle(signal) {
76-
console.log(`Received ${signal}`);
75+
76+
// The signals we want to handle
77+
// NOTE: although it is tempting, the SIGKILL signal (9) cannot be intercepted and handled
78+
var signals = {
79+
'SIGHUP': 1,
80+
'SIGINT': 2,
81+
'SIGTERM': 15
82+
};
83+
function handle(signal, value) {
84+
console.trace(`process received a ${signal} signal with value ${value}`);
85+
try {
86+
server.close((err) => {
87+
console.log(`server stopped by ${signal} with value ${value}`);
88+
console.error(err);
89+
process.exit(128 + value);
90+
})
91+
} catch (error) {
92+
console.error(error);
93+
console.log(`server stopped by ${signal} with value ${value}`);
94+
process.exit(128 + value);
95+
}
7796
}
78-
process.on('SIGTERM', handle);
79-
process.on('SIGINT', handle);
97+
Object.keys(signals).forEach((signal) => process.on(signal, handle));
98+
// process.on('SIGTERM', handle);
99+
// process.on('SIGINT', handle);
80100
// process.on('SIGUSR1', handle);
81101
// process.on('SIGPIPE', handle);
82102
// process.on('SIGHUP', handle);

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.23
1+
1.2.24

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/openflow",
3-
"version": "1.2.23",
3+
"version": "1.2.24",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)