From 24294b22f693b84da4ca237149a2aa0be57ad75e Mon Sep 17 00:00:00 2001 From: Evgeny Date: Mon, 13 Jul 2026 14:32:16 +0300 Subject: [PATCH] fix: use got_initial_pkt instead of new_conn for send_reset decision new_conn is only true for the first INIT after server restart. Subsequent INITs from same peer (recovery loop) see new_conn=0 and revert to old logic, sending 0x05 (no reset) and overwriting the first 0x03 response. got_initial_pkt stays 0 until client actually sends seq=1, so server keeps sending 0x03 across all INIT retries until client resets and starts from seq=1. --- src/etcp_connections.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/etcp_connections.c b/src/etcp_connections.c index 9fd4bec5..3f88fe5b 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -1727,9 +1727,9 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) { // For CHANNEL_INIT (0x04): if link already initialized - no reset, otherwise reset // For INIT_REQUEST (0x02): always reset // Check session_id: if same - no reinit, if different - client restarted, do reinit - if (code == ETCP_INIT_REQUEST || conn->session_id != session_id || new_conn) { - send_reset = 1; // Client explicitly requested reset, or new session, or new server-side connection - DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "do reinit (code=%02x session was %08x now %08x new_conn=%d)", code, conn->session_id, session_id, new_conn); + if (code == ETCP_INIT_REQUEST || conn->session_id != session_id || !conn->got_initial_pkt) { + send_reset = 1; // Client explicitly requested reset, or new session, or server waiting for first packet + DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "do reinit (code=%02x session was %08x now %08x got_init=%d)", code, conn->session_id, session_id, conn->got_initial_pkt); conn->session_id = session_id; etcp_conn_reinit(conn); } else { @@ -1753,9 +1753,9 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) { link->remote_type = req->type; // For new links: reset if client requested or session changed - if (code == ETCP_INIT_REQUEST || conn->session_id != session_id || new_conn) { + if (code == ETCP_INIT_REQUEST || conn->session_id != session_id || !conn->got_initial_pkt) { send_reset = 1; - DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "do reinit for new link (code=%02x session was %08x now %08x new_conn=%d)", code, conn->session_id, session_id, new_conn); + DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "do reinit for new link (code=%02x session was %08x now %08x got_init=%d)", code, conn->session_id, session_id, conn->got_initial_pkt); conn->session_id = session_id; etcp_conn_reinit(conn); }