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