From 15a27131160b4b65fb3f4ae3126d9ed447722453 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Feb 2026 23:13:41 +0000 Subject: [PATCH] Fix client hanging on first operation by queuing message during connect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When no TCP connection exists, send_message_to_server() called tcp_connect() with a NULL output parameter and returned without sending the message. The message was silently dropped, and the only recovery was the 5-second PRIMARY_DEATH_TIMEOUT_SEC retry — causing the client to hang on every cold-connection operation. tcp_connect() already supports returning the output ByteQueue so callers can queue data to be flushed once the connection completes. Use that mechanism: get the output queue from tcp_connect() and write the message into it immediately, so it is sent as soon as the TCP handshake finishes. https://claude.ai/code/session_01EG3WZSH3ZeTdAbb5T42r2w --- src/client.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/client.c b/src/client.c index a07d2fd..95cf160 100644 --- a/src/client.c +++ b/src/client.c @@ -205,32 +205,34 @@ static int leader_idx(ToastyFS *tfs) static void send_message_to_server(ToastyFS *tfs, int server_idx, MessageHeader *msg) { + ByteQueue *output; int conn_idx = tcp_index_from_tag(&tfs->tcp, server_idx); if (conn_idx < 0) { - tcp_connect(&tfs->tcp, tfs->server_addrs[server_idx], server_idx, NULL); - return; + if (tcp_connect(&tfs->tcp, tfs->server_addrs[server_idx], server_idx, &output) < 0) + return; + } else { + output = tcp_output_buffer(&tfs->tcp, conn_idx); + if (output == NULL) + return; } - ByteQueue *output = tcp_output_buffer(&tfs->tcp, conn_idx); - if (output == NULL) - return; - byte_queue_write(output, msg, msg->length); } static void send_message_to_server_ex(ToastyFS *tfs, int server_idx, MessageHeader *msg, void *extra, int extra_len) { + ByteQueue *output; int conn_idx = tcp_index_from_tag(&tfs->tcp, server_idx); if (conn_idx < 0) { - tcp_connect(&tfs->tcp, tfs->server_addrs[server_idx], server_idx, NULL); - return; + if (tcp_connect(&tfs->tcp, tfs->server_addrs[server_idx], server_idx, &output) < 0) + return; + } else { + output = tcp_output_buffer(&tfs->tcp, conn_idx); + if (output == NULL) + return; } - ByteQueue *output = tcp_output_buffer(&tfs->tcp, conn_idx); - if (output == NULL) - return; - byte_queue_write(output, msg, msg->length - extra_len); byte_queue_write(output, extra, extra_len); }