From 69fca2eb69d69a5714e454d37ef09c10dc1b411a Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Mon, 8 Apr 2024 14:18:40 +0500 Subject: [PATCH] Fixed thread_id --- lib/PgSQL_Protocol.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/PgSQL_Protocol.cpp b/lib/PgSQL_Protocol.cpp index 261d2bb02..038f39bc1 100644 --- a/lib/PgSQL_Protocol.cpp +++ b/lib/PgSQL_Protocol.cpp @@ -384,13 +384,19 @@ void PG_pkt::to_PtrSizeArray(PtrSizeArray *psa, unsigned c) { } } -bool PgSQL_Protocol::generate_pkt_initial_handshake(bool send, void** _ptr, unsigned int* len, uint32_t* thread_id, bool deprecate_eof_active) { +bool PgSQL_Protocol::generate_pkt_initial_handshake(bool send, void** _ptr, unsigned int* len, uint32_t* _thread_id, bool deprecate_eof_active) { proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 7, "Generating handshake pkt\n"); PG_pkt pgpkt{}; const int type = 'R'; + uint32_t thread_id = __sync_fetch_and_add(&glovars.thread_id, 1); + if (thread_id == 0) { + thread_id = __sync_fetch_and_add(&glovars.thread_id, 1); // again! + } + *_thread_id = thread_id; + switch ((AUTHENTICATION_METHOD)pgsql_thread___authentication_method) { case AUTHENTICATION_METHOD::NO_PASSWORD: