From d56181503e0e236cf364da8607d1d26dd15512b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Feb 2026 01:02:21 +0000 Subject: [PATCH] Fix cluster not responding after restart Two bugs prevented the cluster from working after a stop/start cycle: 1. tcp_listen_tcp() and tcp_listen_tls() had reuse_addr set to false, causing bind() to fail with EADDRINUSE when ports are in TIME_WAIT state after a restart. Set SO_REUSEADDR to true. 2. The vsr_boot_marker file (created in CWD on first boot) was never cleaned up on cluster stop. On restart, all nodes would enter STATUS_RECOVERY, but since RECOVERY messages are only processed by nodes in STATUS_NORMAL, the entire cluster would deadlock with no node able to recover. Remove the marker in cluster.sh stop. https://claude.ai/code/session_01U72omHJrk95xFwm22Rkqgt --- cluster.sh | 1 + lib/tcp.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cluster.sh b/cluster.sh index 74fbb52..cd8be99 100755 --- a/cluster.sh +++ b/cluster.sh @@ -138,6 +138,7 @@ do_stop() { stop_process "node1" stop_process "node2" stop_process "node3" + rm -f "$SCRIPT_DIR/vsr_boot_marker" echo "Cluster stopped." } diff --git a/lib/tcp.c b/lib/tcp.c index 229ff09..51eba33 100644 --- a/lib/tcp.c +++ b/lib/tcp.c @@ -282,7 +282,7 @@ int tcp_listen_tcp(TCP *tcp, Address addr) return -1; // TODO: Make these configurable - bool reuse_addr = false; + bool reuse_addr = true; int backlog = 32; SOCKET fd = create_listen_socket(addr, reuse_addr, backlog); @@ -302,7 +302,7 @@ int tcp_listen_tls(TCP *tcp, Address addr, string cert_file, string key_file) return -1; // TODO: Make these configurable - bool reuse_addr = false; + bool reuse_addr = true; int backlog = 32; SOCKET fd = create_listen_socket(addr, reuse_addr, backlog);