Skip to content

Commit

Permalink
enable quicker tcp error notification
Browse files Browse the repository at this point in the history
Fixes: #652
Relates to: #648

When a connection between controller and agent is esablished and
is dropped later, e.g. removing the cable from the agent, the
disconnect is properly detected by the keepalive mechanism.
However, the keepalive takes a while to detect this (based on the
KEEPCNT of the system). If any command is issued during that time
frame, tcp will try to retransmit the data. Eventually, retransmitting
will be stopped and ICMP packets for host not reachable emitted.
The keepalive is not used then, which results in the connection
between agent and controller to be broken but not closed - a
disconnect is not detected.
By setting the IP_RECVERR socket option, errors such as the ICMP
host not reachable error will be delivered to the upper layer
(systemd event loop in our case) so that it can handle it.

Signed-off-by: Michael Engel <[email protected]>
  • Loading branch information
engelmi committed Dec 18, 2023
1 parent f7b2272 commit 5502e9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/libbluechi/bus/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ int bus_socket_set_keepalive(sd_bus *bus) {
return -errno;
}

int enable = 1;
r = setsockopt(fd, IPPROTO_IP, IP_RECVERR, &enable, sizeof(int));
if (r < 0) {
return -errno;
}

return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/manager/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ static int manager_accept_node_connection(

int r = bus_socket_set_no_delay(dbus_server);
if (r < 0) {
bc_log_warn("Failed to set NO_DELAY on socket");
bc_log_warnf("Failed to set NO_DELAY on socket: %s", strerror(-r));
}
r = bus_socket_set_keepalive(dbus_server);
if (r < 0) {
bc_log_warn("Failed to set KEEPALIVE on socket");
bc_log_warnf("Failed to set KEEPALIVE on socket: %s", strerror(-r));
}

/* Add anonymous node */
Expand Down

0 comments on commit 5502e9e

Please sign in to comment.