From 8e1e5652ee2d9c283ecbe5a375fb67068280cb41 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Tue, 23 Nov 2021 11:21:38 -0600 Subject: [PATCH] network: detect if socket has been invalidated Signed-off-by: Eduardo Silva --- src/flb_network.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/flb_network.c b/src/flb_network.c index d25ab457470..736de2601ed 100644 --- a/src/flb_network.c +++ b/src/flb_network.c @@ -444,6 +444,16 @@ static int net_connect_async(int fd, /* Save the mask before the event handler do a reset */ mask = u_conn->event.mask; + /* + * If the socket has been invalidated (e.g: timeout or shutdown), just + * print a debug message and return. + */ + if (u_conn->fd == -1) { + flb_debug("[net] TCP connection not longer available: %s:%i", + u->tcp_host, u->tcp_port); + return -1; + } + /* We got a notification, remove the event registered */ ret = mk_event_del(u_conn->evl, &u_conn->event); if (ret == -1) {