Skip to content

Commit

Permalink
io: added code to detect non-recoverable connection errors
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Alminana <[email protected]>
  • Loading branch information
leonardo-albertovich authored and edsiper committed Aug 31, 2023
1 parent f0e9275 commit f7637f0
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/flb_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ int flb_io_net_connect(struct flb_connection *connection,
return 0;
}

static void net_io_propagate_critical_error(
struct flb_connection *connection)
{
switch (errno) {
case EBADF:
case ECONNRESET:
case EDESTADDRREQ:
case ENOTCONN:
case EPIPE:
case EACCES:
case EIO:
case ENETDOWN:
case ENETUNREACH:
connection->net_error = errno;
}
}

static int fd_io_write(int fd, struct sockaddr_storage *address,
const void *data, size_t len, size_t *out_len);
static int net_io_write(struct flb_connection *connection,
Expand Down Expand Up @@ -204,7 +221,13 @@ static int net_io_write(struct flb_connection *connection,
}
}

return fd_io_write(connection->fd, address, data, len, out_len);
ret = fd_io_write(connection->fd, address, data, len, out_len);

if (ret == -1) {
net_io_propagate_critical_error(connection);
}

return ret;
}

static int fd_io_write(int fd, struct sockaddr_storage *address,
Expand Down Expand Up @@ -430,6 +453,7 @@ static FLB_INLINE int net_io_write_async(struct flb_coro *co,
*out_len = total;

net_io_restore_event(connection, &event_backup);
net_io_propagate_critical_error(connection);

return -1;
}
Expand Down Expand Up @@ -519,6 +543,9 @@ static ssize_t net_io_read(struct flb_connection *connection,
connection->net->io_timeout,
flb_connection_get_remote_address(connection));
}
else {
net_io_propagate_critical_error(connection);
}

return -1;
}
Expand Down

0 comments on commit f7637f0

Please sign in to comment.