diff --git a/image_puller/TCPImagePuller.cpp b/image_puller/TCPImagePuller.cpp index 7f93b561..b0848381 100644 --- a/image_puller/TCPImagePuller.cpp +++ b/image_puller/TCPImagePuller.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -227,6 +228,19 @@ bool TCPImagePuller::EnsureConnected() { if (receive_buffer_size) setsockopt(new_fd, SOL_SOCKET, SO_RCVBUF, &receive_buffer_size.value(), sizeof(int32_t)); + // OS-level TCP keep-alive: detect a silently-dead pusher (no RST, e.g. crash or + // network partition) even while recv() is blocked in a long inter-image gap. Mirror + // the pusher's settings so detection is symmetric (~60s) and stays well clear of the + // 250 ms app-level BUSY heartbeat. + int one = 1; + setsockopt(new_fd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one)); + int idle = 30; + int intvl = 10; + int cnt = 3; + setsockopt(new_fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)); + setsockopt(new_fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)); + setsockopt(new_fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)); + if (connect(new_fd, ai->ai_addr, ai->ai_addrlen) == 0) break;