Skip to content

Commit

Permalink
in_forward: fix handling of TCP connections on SIGTERM (#2610)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
edsiper committed Nov 18, 2021
1 parent 0ba2dc2 commit c139ea0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions plugins/in_forward/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}

Expand All @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions plugins/in_forward/fw_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions plugins/in_forward/fw_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c139ea0

Please sign in to comment.