Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wlUG0-000Cbj-0k for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Jul 2026 16:20:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wlUFx-001Dgv-1s for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Jul 2026 16:20:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wlUFx-001Dgn-0l for pgsql-bugs@lists.postgresql.org; Sun, 19 Jul 2026 16:20:44 +0000 Received: from mail-vk1-xa36.google.com ([2607:f8b0:4864:20::a36]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wlUFt-00000000zOi-3mhj for pgsql-bugs@lists.postgresql.org; Sun, 19 Jul 2026 16:20:43 +0000 Received: by mail-vk1-xa36.google.com with SMTP id 71dfb90a1353d-5bdff8c02b2so2884520e0c.3 for ; Sun, 19 Jul 2026 09:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784478040; x=1785082840; darn=lists.postgresql.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=d2gPclOLUfu6LqvEgONXz/NH7IWZT1fNAGPEJxsQQ6M=; b=O0LPFJI3iNDS+DVKPV5crG4983XDAxbTFmsiDL4Gv95zn9m95UM9VHZA0eK5Pgdzfd 13U0UlNWcV5MWaT5cG2bHfIJb+5u/XLL4OzjXTghhheyPnUW3aLaB61w9EhtdQs/iQba m1nJeSwwrU9DiRbvng2AVg6tl/ftPl1XcPaTIaMntsFAWD0pTf4I/qYAm+du2wkp1+pJ SmJHUHWJMpKvdIgblh4yucJOAZyu/q9R3IwQLeLhTaEIP9sBI0LPKuL5kf+0WCPOHmFC tF7k30AyailWtJwS8ycKni2YuAi5gvZzxkRCKgzpFSIkTrbNBsA9Ke4814AxRRUhOdx/ yoqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784478040; x=1785082840; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=d2gPclOLUfu6LqvEgONXz/NH7IWZT1fNAGPEJxsQQ6M=; b=O1lPxOAsDaXysrCDj2RbR4cbTlMx4/cjTNUH5QW2IQr0kP9dBhlqw3+Vst5C/a2rXO EyFiU+MyAQezY7VGrBUBBSzyuIiWbRccDfEzzdlYBxJ/euUQht0C40XyFyasNg+nYF51 hAZJApIQjf/BZlOb/TYlWMvVaD9x73cuyj755aKqmIttOJR2LHaucxTYRuRxg868wu4E AqNLTY8AoC6ZIPovDGYx61xjgx5ifY/aMP2y/GirmLWVrgay4nYj+TMjeAfJXU0FM3+I gQcN54pO1JTByjE69gIvXBTmnDx4yOin2SmwtY8z3u9EW/xEmqunO8oRLs7XQjCwuV7m CmnA== X-Gm-Message-State: AOJu0YwM0ouhTAxt8uwlE8GXRghKq1cPX0iXuM60+GIUfBpH/UnXK2P/ U+61XDDnKRCrUFy/GbJC4Cw68hizV8GI56xiS0BESc1dv0+yUCVVvPzPQfpjA5cz X-Gm-Gg: AfdE7ckPuhM8JfilEIyP55g8qfa9czHZA8lzRG6wyPOd5+dbNEE/1CpRUGDIBsVfIEs 93ciE5acVmMoTvKC0F48LJWSHgq0l/VmiWtrP42rpM5e8EaiWrFI//6ftAki/h2XBIoF9TOy5At qF6XlVhtoEBGO6euttu2DPbjZUMbXzmxHkyFBzqJbXzZ/Dyk5F3lQKO3DLzfxMo1w2XAgf0Od9W GqAWW30KN7guUkyjLa+VS1imTOmoaOhpVlKPhn+a2+91MXkgPNK3LcU7SBWAhnU5ZebXX6R+Xdy AjOCzWZJlUqu3OFVb6NOT64J0J4G4/nu3jXQMjUPcGs0RArj+CNPdwk0C7yXnFiWaLjjfK0ilFZ 9i91XveXrJ5wJfHYVynR79cqMhXgxM8vsqwR6wT/Gs4rMxT3xuNtW8Z9yDnWEkYZ5hDkdgiJTMQ YHO3diG+t+yHtVmXyU3128WMoyHj3z4auAxD9Utpa4QnVRTsTbDYYq X-Received: by 2002:a05:6122:8b11:b0:5bf:b3a0:388c with SMTP id 71dfb90a1353d-5c1b6785adfmr1937532e0c.6.1784478040057; Sun, 19 Jul 2026 09:20:40 -0700 (PDT) Received: from [192.168.1.7] ([179.0.56.242]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5c1eee43c99sm6193715e0c.7.2026.07.19.09.20.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 Jul 2026 09:20:39 -0700 (PDT) Message-ID: <660f580d-d47c-418b-8caf-6228c1e1b4e9@gmail.com> Date: Sun, 19 Jul 2026 13:20:36 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Danimar Ribeiro Subject: Re: BUG #19424: Concurrent PQconnectdb() calls hang on Windows To: pgsql-bugs@lists.postgresql.org Cc: david.ritter@gmail.com References: <19424-0ab4342f914b6296@postgresql.org> Content-Language: pt-BR In-Reply-To: <19424-0ab4342f914b6296@postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Mar 3, 2026 at 4:23 PM, David Ritter wrote: > The following bug has been logged on the website: > > Bug reference: 19424 > Logged by: David Ritter > Email address: david.ritter@gmail.com > PostgreSQL version: 18.3 > Operating system: Windows 11 > Description: > > Versions affected: libpq 17.4, 18.3 (likely all 17.x+) > > Platform: Windows (MSVC 19.x, x86_64). Not reproducible on Linux (RHEL 9, > tested 1000 runs with 100 threads each). > > Description: When multiple threads each call PQconnectdb() concurrently with > independent connection strings, most or all threads hang indefinitely. > PQisthreadsafe() returns 1. A single serial warmup connection succeeds. The > attached reproducer spawns N threads and reports how many complete within 30 > seconds. > > Hi David, I was looking into this report and tried to reproduce the issue on Windows 11 with MSVC, testing against both the latest master and REL_17_STABLE. It turns out this isn't a bug in libpq, but rather a limitation in the Windows API used within the test reproducer script itself. The `WaitForMultipleObjects` function in Windows has a hardcoded limit of `MAXIMUM_WAIT_OBJECTS` (which is 64). Because the script passes 100 threads to it at once, the function fails and returns instantly. Consequently, the script's timer immediately ends while the threads are still spinning up, reading their `done` flags as 0. The script misinterprets this instant API failure as a 30-second timeout/hang. I modified the test script to wait in chunks of 60 threads to bypass the Windows limit: for (i = 0; i < num_threads; i += 60) { int chunk_size = (num_threads - i > 60) ? 60 : (num_threads - i); WaitForMultipleObjects(chunk_size, &threads[i], TRUE, TIMEOUT_SECONDS * 1000); } After applying this fix to the test script, I ran it with 300 concurrent threads. The issue disappears completely, and the result is `300 OK` with zero hung threads. libpq handles the concurrency safely on Windows. Are you still experiencing this issue in your actual application? If so, could you provide an updated script to replicate the issue? I would be happy to test it again. Regards Danimar