pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix "invalid spinlock number: 0" error in pg_stat_wal_receiver.
Date: Thu, 18 Feb 2021 14:31:07 +0000
Message-ID: <E1lCkKh-0007SC-AC@gemulon.postgresql.org> (raw)

Fix "invalid spinlock number: 0" error in pg_stat_wal_receiver.

Commit 2c8dd05d6c added the atomic variable writtenUpto into
walreceiver's shared memory information. It's initialized only
when walreceiver started up but could be read via pg_stat_wal_receiver
view anytime, i.e., even before it's initialized. In the server built
with --disable-atomics and --disable-spinlocks, this uninitialized
atomic variable read could cause "invalid spinlock number: 0" error.

This commit changed writtenUpto so that it's initialized at
the postmaster startup, to avoid the uninitialized variable read
via pg_stat_wal_receiver and fix the error.

Also this commit moved the read of writtenUpto after the release
of spinlock protecting walreceiver's shared variables. This is
necessary to prevent new spinlock from being taken by atomic
variable read while holding another spinlock, and to shorten
the spinlock duration. This change leads writtenUpto not to be
consistent with the other walreceiver's shared variables protected
by a spinlock. But this is OK because writtenUpto should not be
used for data integrity checks.

Back-patch to v13 where commit 2c8dd05d6c introduced the bug.

Author: Fujii Masao
Reviewed-by: Michael Paquier, Thomas Munro, Andres Freund
Discussion: https://postgr.es/m/7ef8708c-5b6b-edd3-2cf2-7783f1c7c175@oss.nttdata.com

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d4b667e9353a70c4ee2847603e5ad2e14e20f82e

Modified Files
--------------
src/backend/replication/walreceiver.c      | 11 +++++++++--
src/backend/replication/walreceiverfuncs.c |  1 +
src/test/regress/expected/sysviews.out     |  7 +++++++
src/test/regress/sql/sysviews.sql          |  3 +++
4 files changed, 20 insertions(+), 2 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1lCkKh-0007SC-AC@gemulon.postgresql.org>
Permalink:  ../E1lCkKh-0007SC-AC@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lCkKh-0007SC-AC@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: fujii@postgresql.org
  Subject: Re: pgsql: Fix "invalid spinlock number: 0" error in pg_stat_wal_receiver.
  In-Reply-To: <E1lCkKh-0007SC-AC@gemulon.postgresql.org>
  References: <E1lCkKh-0007SC-AC@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox