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 1w370V-000uWa-0s for pgpool-hackers@arkaria.postgresql.org; Thu, 19 Mar 2026 06:37:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w370U-00GlQ9-0u for pgpool-hackers@arkaria.postgresql.org; Thu, 19 Mar 2026 06:37:22 +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 1w370U-00GlQ2-0N for pgpool-hackers@lists.postgresql.org; Thu, 19 Mar 2026 06:37:22 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w370Q-00000000UU3-0rWg for pgpool-hackers@lists.postgresql.org; Thu, 19 Mar 2026 06:37:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:To:Message-Id:Date:Sender: Reply-To:Cc:Content-ID:Content-Description; bh=CXVrbmdK9sZatQP7vDlGg2ULZTMdDYnRncdovoeLGdk=; b=GtEwbgf00u6BpioDvrJ9Z6PJpV G41swy5u6UQSH20AFYB2piaRCUR6brtqXyq1h6mTWqwUWSIhrrlvQ9LJ78U+/BnIQ6BClAMmj02Zr yRpqX//fIIDs3O8Reo1sXv8lxyF7Uea2lJw/jFD+D7N4Fiq1axocQESY8LriMjb6vze5P1/7FmED4 FZuJZofHVQ1b4iPYf2gXX3CaluGiLZ46UZiJpftxfeECHbeO++1TZhVty/Ou8n6yhMeaIJI4vS85F cbIVVj0pWknuKfMk/FEI3FsDime65bSZiHLsNoxDLWxGSzWZ+lwhDZ4KB0WfdmF1w7PnkjIv/MXJ4 3zOu787A==; Received: from [2409:11:4120:300:41fc:6352:b3cb:ee23] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w370N-003Gje-2F for pgpool-hackers@lists.postgresql.org; Thu, 19 Mar 2026 06:37:18 +0000 Date: Thu, 19 Mar 2026 15:37:04 +0900 (JST) Message-Id: <20260319.153704.1746090050786287316.ishii@postgresql.org> To: pgpool-hackers@lists.postgresql.org Subject: Re: Lock release leak in pool_search_relcache From: Tatsuo Ishii In-Reply-To: <20260317.182615.1046517700474336117.ishii@postgresql.org> References: <20260317.182615.1046517700474336117.ishii@postgresql.org> X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:41fc:6352:b3cb:ee23 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > While looking into src/utils/pool_relcache.c for other reasons, I > noticed pool_search_relcache does not release lock in a certain code > path. When the local relation cache does not hit, it searches the > shared relation cache if enable_shared_relcache is on. If the lock for > query cache has been already held (thus the variable "locked" is set > to true), it acquires a shared lock, then releases it and acquires an > exclusive lock to call pool_catalog_commit_cache. Since in this code > path variable "locked" is set to true, subsequent code: > > if (pool_config->enable_shared_relcache && !locked) > { > pool_shmem_unlock(); > POOL_SETMASK(&oldmask); > } > > does not reach inside the if statement -- lock is not released. I > think to fix this, the following code requires "locked = false;" > > pool_shmem_unlock(); > pool_shmem_lock(POOL_MEMQ_EXCLUSIVE_LOCK); > pool_catalog_commit_cache(backend, query, query_cache_data, query_cache_len); > > Attached patch does this. Plus following changes are made in the patch: > > - the variable name "locked" is confusing. To clarify the role of the > variable, its name is changed to "locked_by_others". > > - Fix per_node_statement_log is called even though actual query is > not sent to backend. Pushed down to v4.4 stable. Best regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp