When a stats entry is reinitialized and dropped again while a backend still holds a reference from an older generation, the backend releasing the last reference found a generation mismatch and left behind an entry marked as dropped with a refcount of 0. Nothing would free it, and the checkpointer would trigger an assertion at shutdown when flushing the stats. Looking more at the issue, using some hardcoded sleeps before the dshash_find() that takes an exclusive lock when releasing an entry with some concurrent activity, there was more going on: - A missing entry could be reported as an error at backend exit, error that should not be hit even if the entry was reinitialized and dropped concurrently. - The generation check was not correct for the case of 0 due to the first issue. A generation of 0 refers to an entry that has been freshly created. This commit reworks the entry release to be safer concurrent-wise when an entry targetted for release is found as already existing: - If marked as dropped without refount at 0, free it. - In other cases, ignore it. The entry has been reinitialized or created again with the same key, and is still in use. Sami has posted a basic test case (equivalent added in this commit) that gives a way to reproduce the assertion failure on backend exit, which is a consequence of the incorrect handling of entry releases. Reported-by: Sami Imseih <samimseih.pg@gmail.com> Reviewed-by: Sami Imseih <samimseih.pg@gmail.com> Discussion: https://postgr.es/m/CAN12+YJXE+rEOVo74uM5Ofbj_t_m0DHvd_Mo4ppeHV=aDvvXoQ@mail.gmail.com Backpatch-through: 15
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/17/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/17/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.