Fix client hanging on first operation by queuing message during connect
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
This commit is contained in:
+10
-8
@@ -205,15 +205,16 @@ 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);
|
||||
if (tcp_connect(&tfs->tcp, tfs->server_addrs[server_idx], server_idx, &output) < 0)
|
||||
return;
|
||||
}
|
||||
|
||||
ByteQueue *output = tcp_output_buffer(&tfs->tcp, conn_idx);
|
||||
} else {
|
||||
output = tcp_output_buffer(&tfs->tcp, conn_idx);
|
||||
if (output == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
byte_queue_write(output, msg, msg->length);
|
||||
}
|
||||
@@ -221,15 +222,16 @@ static void send_message_to_server(ToastyFS *tfs, int server_idx, MessageHeader
|
||||
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);
|
||||
if (tcp_connect(&tfs->tcp, tfs->server_addrs[server_idx], server_idx, &output) < 0)
|
||||
return;
|
||||
}
|
||||
|
||||
ByteQueue *output = tcp_output_buffer(&tfs->tcp, conn_idx);
|
||||
} else {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user