Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/fluent-bit/flb_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/flb_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@ void flb_connection_unset_io_timeout(struct flb_connection *connection)
assert(connection != NULL);

connection->ts_io_timeout = -1;
}
}
4 changes: 4 additions & 0 deletions src/flb_downstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Comment on lines +212 to +214

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wire the drop callback for downstream owners

This call does not currently notify any owner because the new field is never assigned anywhere in the tree (rg "drop_notification_callback\\s*=" finds no setters). In the HTTP server path, sessions still retain session->connection/connection->user_data when the connection is attached (src/http_server/flb_http_server.c:275-281), and later unconditionally release that pointer during session destroy (src/http_server/flb_http_server.c:512-513); if flb_downstream_conn_timeouts() drops the downstream connection first (src/flb_downstream.c:515-516), the session is left with a stale connection pointer. Please register the callback where downstream sessions are attached, or the added notification mechanism will not prevent the timeout/use-after-free case it is meant to handle.

Useful? React with 👍 / 👎.


if (MK_EVENT_IS_REGISTERED((&connection->event))) {
mk_event_del(connection->evl, &connection->event);
}
Expand Down
Loading