diff --git a/include/fluent-bit/flb_connection.h b/include/fluent-bit/flb_connection.h index 53f28b974e4..31801e71e09 100644 --- a/include/fluent-bit/flb_connection.h +++ b/include/fluent-bit/flb_connection.h @@ -58,12 +58,26 @@ struct flb_net_setup; struct flb_upstream; struct flb_downstream; struct flb_tls_session; +struct flb_connection; + +typedef void (*flb_connection_drop_notification_callback)( + struct flb_connection *connection); /* Base network connection */ struct flb_connection { struct mk_event event; void *user_data; + /* + * Optional notification invoked from prepare_destroy_conn() while the + * connection is still linked on busy_queue and before the event is + * deregistered and the file descriptor is closed. + * + * Callers may detach external state here, but must not free, destroy or + * unlink the connection because prepare_destroy_conn() performs the final + * teardown immediately after the callback returns. + */ + flb_connection_drop_notification_callback drop_notification_callback; /* Socket */ flb_sockfd_t fd; diff --git a/src/flb_connection.c b/src/flb_connection.c index a3ed402651b..34b1cc229c7 100644 --- a/src/flb_connection.c +++ b/src/flb_connection.c @@ -254,4 +254,4 @@ void flb_connection_unset_io_timeout(struct flb_connection *connection) assert(connection != NULL); connection->ts_io_timeout = -1; -} \ No newline at end of file +} diff --git a/src/flb_downstream.c b/src/flb_downstream.c index 34c37d0851d..1de1376cd26 100644 --- a/src/flb_downstream.c +++ b/src/flb_downstream.c @@ -209,6 +209,10 @@ static int prepare_destroy_conn(struct flb_connection *connection) flb_trace("[downstream] destroy connection #%i to %s", connection->fd, flb_connection_get_remote_address(connection)); + if (connection->drop_notification_callback != NULL) { + connection->drop_notification_callback(connection); + } + if (MK_EVENT_IS_REGISTERED((&connection->event))) { mk_event_del(connection->evl, &connection->event); }