Re: 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Mikhail Kot <mikhail.kot@databricks.com>
Cc: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>, Rider <oceanustz@gmail.com>, Steven Niu <niushiji@gmail.com>
Date: 2025-09-08T07:54:16Z
Lists: pgsql-hackers
On Sat, Sep 06, 2025 at 10:01:24AM +0900, Michael Paquier wrote: > A last thing that I was not able to spend much time on is how much it > is possible to mess up with the shared memory state. If it is worse > than I suspected initially, where an OOM in a first session can cause > crashes because of incorrect dshash entries in shmem depending on the > stats kind fetched, a backpatch will be required, indeed. The change > is not really invasive, so that's OK on this side. OK, I have played a bit more with all that, corrupting the shared hashtable of pgstats. At the end, I have used a version close to what I have sent previously that changes pgstat_init_entry() to return NULL on OOM with dsa_allocate_extended(), as any other possible errors that could happen in this call involve elog(ERROR) and not-reachable cases. pgstat_read_statsfile() has been changed to raise an ERROR instead, which is what we did previously, giving priority to the on-disk stats when the environment is under memory pressure at startup. The patch has required a few tweaks in the back-branches, nothing huge. Thanks for the report! -- Michael
Commits
-
Fix corruption of pgstats shared hashtable due to OOM failures
- 1852ec5db5d8 15.15 landed
- 12f57681c79b 16.11 landed
- 3e6dfcfb0529 17.7 landed
- f256a7bba728 18.0 landed
- 8191e0c16a03 19 (unreleased) landed