diff --git a/include/fluent-bit/flb_upstream_conn.h b/include/fluent-bit/flb_upstream_conn.h index e93e8e51b18..08e2741cef7 100644 --- a/include/fluent-bit/flb_upstream_conn.h +++ b/include/fluent-bit/flb_upstream_conn.h @@ -46,6 +46,9 @@ struct flb_upstream_conn { /* Keepalive */ int ka_count; /* how many times this connection has been used */ + /* do we need to mk_event_del the keepalive event on clean up*/ + int ka_dropped_event_added; + /* * Custom 'error' for the connection file descriptor. Commonly used to * specify a reason for an exception that was generated locally: consider diff --git a/src/flb_upstream.c b/src/flb_upstream.c index df0f2c32042..3fc700e98fc 100644 --- a/src/flb_upstream.c +++ b/src/flb_upstream.c @@ -429,7 +429,7 @@ static int prepare_destroy_conn(struct flb_upstream_conn *u_conn) flb_trace("[upstream] destroy connection #%i to %s:%i", u_conn->fd, u->tcp_host, u->tcp_port); - if (u->flags & FLB_IO_ASYNC) { + if (u->flags & FLB_IO_ASYNC || u_conn->ka_dropped_event_added == FLB_TRUE) { mk_event_del(u_conn->evl, &u_conn->event); } @@ -514,6 +514,8 @@ static struct flb_upstream_conn *create_conn(struct flb_upstream *u) conn->net_error = -1; conn->busy_flag = FLB_TRUE; + conn->ka_dropped_event_added = FLB_FALSE; + /* retrieve the event loop */ evl = flb_engine_evl_get(); conn->evl = evl; @@ -769,6 +771,7 @@ int flb_upstream_conn_release(struct flb_upstream_conn *conn) conn->fd, conn->u->tcp_host, conn->u->tcp_port); return prepare_destroy_conn_safe(conn); } + conn->ka_dropped_event_added = FLB_TRUE; flb_debug("[upstream] KA connection #%i to %s:%i is now available", conn->fd, conn->u->tcp_host, conn->u->tcp_port);