From 6a3a824a18bc782788777c3a26a0d9d3f9dca33e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20S=C3=A1nchez=20Parra?= Date: Mon, 10 Oct 2022 21:02:27 +0200 Subject: [PATCH] Fix sequence id in EOF to OK packet conversion #3698 Fix invalid resultset when using query cache and mixing clients using and not using CLIENT_DEPRECATE_EOF. If a client connects to ProxySQL not using CLIENT_DEPRECATE_EOF and it caches a resultset, when a client using CLIENT_DEPRECATE_EOF executes the same query it will get an invalid resultset and the client will disconnect. The data in the resultset is correct, but proxysql skips a sequence id thus the client assumes it is corrupted. --- lib/Query_Cache.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Query_Cache.cpp b/lib/Query_Cache.cpp index de2dd7152..c20ac38a9 100644 --- a/lib/Query_Cache.cpp +++ b/lib/Query_Cache.cpp @@ -519,6 +519,18 @@ unsigned char* eof_to_ok_packet(QC_entry_t* entry) { memcpy(vp, it, 4); // ======================================= + // Decrement ids after the first EOF + unsigned char* dp = result + entry->column_eof_pkt_offset; + mysql_hdr decrement_hdr; + for (;;) { + memcpy(&decrement_hdr, dp, sizeof(mysql_hdr)); + decrement_hdr.pkt_id--; + memcpy(dp, &decrement_hdr, sizeof(mysql_hdr)); + dp += sizeof(mysql_hdr) + decrement_hdr.pkt_length; + if (dp >= vp) + break; + } + return result; }