Re: BUG #17372: Altering statistics during concurrent drop can lead to a server crash - Mailing list pgsql-bugs

From Tomas Vondra
Subject Re: BUG #17372: Altering statistics during concurrent drop can lead to a server crash
Date
Msg-id 2615f158-b790-4176-11ad-9711e4fd56c7@enterprisedb.com
Whole thread Raw
In response to BUG #17372: Altering statistics during concurrent drop can lead to a server crash  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #17372: Altering statistics during concurrent drop can lead to a server crash  (Alexander Lakhin <exclusion@gmail.com>)
List pgsql-bugs
On 1/20/22 05:00, PG Bug reporting form wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      17372
> Logged by:          Alexander Lakhin
> Email address:      exclusion@gmail.com
> PostgreSQL version: 14.1
> Operating system:   Ubuntu 20.04
> Description:        
> 
> The following script (based on the stats_ext test):
> psql -c "CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);"
> for i in `seq 100`; do
> echo "iteration $i"
> ( { for n in `seq 20`; do echo "CREATE STATISTICS ab1_a_b_stats ON a, b FROM
> ab1; DROP STATISTICS ab1_a_b_stats;"; done } | psql ) >psql1.log 2>&1 &
> ( { for n in `seq 20`; do echo "ALTER STATISTICS ab1_a_b_stats SET
> STATISTICS -1;"; done } | psql ) >psql2.log 2>&1 &
> 
> wait
> sleep 2
> coredumpctl --no-pager && break
> done
> 

Thanks for the report - I've reproduced it using your script (I had to
add a short wait before the syscache lookup). The issue is fairly
simple, we never check we actually found a tuple in the syscache, i.e.
there's no HeapTupleIsValid() call. We check the OID earlier, but the
tuple may have disappeared since then.

IMO the usual "cache lookup failed" error that we throw in other places
in similar cases is good enough. We already fail with other errors
(tuple concurrently updated/deleted) here.

Patch attached.


regards

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachment

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #17375: RECOVERY TARGET TIME RESTORE IS FAILING TO START SERVER
Next
From: Liam Bowen
Date:
Subject: Further information on BUG #17299: Exit code 3 when open connections concurrently (PQisthreadsafe() == 1)