From a1bb8ab06000138b440d0add4278f7466dea8b0f Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Wed, 17 Nov 2021 22:42:56 -0600 Subject: [PATCH] in_forward: fix handling of TCP connections on SIGTERM (#2610) When Fluent Bit receives a SIGTERM, internally it was only taking care of the server socket leaving the active connections in an open state. This patch changes that behavior and if the plugin is paused or if the engine receives SIGTERM (which will trigger a pause), now the agent will drop the active TCP connections. Signed-off-by: Eduardo Silva --- plugins/in_forward/fw.c | 8 +++++--- plugins/in_forward/fw_conn.c | 14 ++++++++++++++ plugins/in_forward/fw_conn.h | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/plugins/in_forward/fw.c b/plugins/in_forward/fw.c index 52dcba04c83..198ef904049 100644 --- a/plugins/in_forward/fw.c +++ b/plugins/in_forward/fw.c @@ -186,6 +186,8 @@ static void in_fw_pause(void *data, struct flb_config *config) */ if (config->is_ingestion_active == FLB_FALSE) { mk_event_closesocket(ctx->server_fd); + fw_conn_del_all(ctx); + } } @@ -197,11 +199,11 @@ static int in_fw_exit(void *data, struct flb_config *config) struct flb_in_fw_config *ctx = data; struct fw_conn *conn; - mk_list_foreach_safe(head, tmp, &ctx->connections) { - conn = mk_list_entry(head, struct fw_conn, _head); - fw_conn_del(conn); + if (!ctx) { + return 0; } + fw_conn_del_all(ctx); fw_config_destroy(ctx); return 0; } diff --git a/plugins/in_forward/fw_conn.c b/plugins/in_forward/fw_conn.c index 851b5d7fd76..b8711a5d31a 100644 --- a/plugins/in_forward/fw_conn.c +++ b/plugins/in_forward/fw_conn.c @@ -161,3 +161,17 @@ int fw_conn_del(struct fw_conn *conn) return 0; } + +int fw_conn_del_all(struct flb_in_fw_config *ctx) +{ + struct mk_list *tmp; + struct mk_list *head; + struct fw_conn *conn; + + mk_list_foreach_safe(head, tmp, &ctx->connections) { + conn = mk_list_entry(head, struct fw_conn, _head); + fw_conn_del(conn); + } + + return 0; +} \ No newline at end of file diff --git a/plugins/in_forward/fw_conn.h b/plugins/in_forward/fw_conn.h index c89da9669b0..c3c8cf4ad63 100644 --- a/plugins/in_forward/fw_conn.h +++ b/plugins/in_forward/fw_conn.h @@ -54,5 +54,6 @@ struct fw_conn { struct fw_conn *fw_conn_add(int fd, struct flb_in_fw_config *ctx); int fw_conn_del(struct fw_conn *conn); +int fw_conn_del_all(struct flb_in_fw_config *ctx); #endif