Skip to content

Commit da91c49

Browse files
author
Lukas Hutak
committed
Core: process remaining flow records on termination (SIGINT, SIGTERM)
Until now, when an external signal was received, the collector was quickly terminated and the received but not yet processed flow records were discarded. Now, when a signal is received, there is a gradual termination where the reception of new flow records is terminated but all records received so far are fully processed. Only if the termination signal arrives a second time the processing of unprocessed records will be also interrupted.
1 parent 47bf8aa commit da91c49

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/core/configurator/configurator.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,22 @@ termination_handler(int sig)
7373

7474
// In case we change 'errno' (e.g. write())
7575
int errno_backup = errno;
76+
enum ipx_cpipe_type request_type = IPX_CPIPE_TYPE_TERM_SLOW;
7677
static int cnt = 0;
7778

78-
if (cnt > 0) {
79+
if (cnt == 1) {
80+
static const char *msg = "Another termination signal detected. Skipping unprocess data...\n";
81+
write(STDERR_FILENO, msg, strlen(msg));
82+
request_type = IPX_CPIPE_TYPE_TERM_FAST;
83+
} else if (cnt > 1) {
7984
static const char *msg = "Another termination signal detected. Quiting without cleanup...\n";
80-
write(STDOUT_FILENO, msg, strlen(msg));
85+
write(STDERR_FILENO, msg, strlen(msg));
8186
abort();
8287
}
8388
cnt++;
8489

8590
// Send a termination request to the configurator
86-
int rc = ipx_cpipe_send_term(NULL, IPX_CPIPE_TYPE_TERM_FAST);
91+
int rc = ipx_cpipe_send_term(NULL, request_type);
8792
if (rc != IPX_OK) {
8893
static const char *msg = "ERROR: Signal handler: failed to send a termination request";
8994
write(STDOUT_FILENO, msg, strlen(msg));

src/core/configurator/cpipe.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ enum ipx_cpipe_type {
6060
* @brief Fast termination request
6161
*
6262
* Request to terminate the collector as fast as possible. Usually this request should be
63-
* send in case of a fatal failure of any plugin instance (by a particular instance thread)
64-
* or on a user request to terminate the collector (e.g. SIGINT/SIGTERM signals).
63+
* send in case of a fatal failure of any plugin instance (by a particular instance thread).
6564
*
6665
* As a reaction to this request the configurator will force stop calling processing functions
6766
* of ALL plugin instances (i.e. ipx_plugin_get() and ipx_plugin_process() callbacks) and send

0 commit comments

Comments
 (0)