pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Simon Riggs <simon.riggs@enterprisedb.com>
Cc: Michael Harris <harmic@gmail.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Undetected Deadlock
Date: Thu, 03 Feb 2022 11:36:27 -0500
Message-ID: <272367.1643906187@sss.pgh.pa.us> (raw)
In-Reply-To: <CANbhV-FoXqh3YWuJLoH-36Mb+gwXG4XQdSy=9x-Zv72BFGhVww@mail.gmail.com>
References: <CADofcAWbMrvgwSMqO4iG_iD3E2v8ZUrC-_crB41my=VMM02-CA@mail.gmail.com>
	<202201252311.4jc4gpdzwwu7@alvherre.pgsql>
	<CADofcAXSn_oS3MOxS=1epiXirwETOB_BpBmM8w4=F3GaQe+cwA@mail.gmail.com>
	<CADofcAV29umxzTFPuJu+Cvvd5cZKkQxK0TZmpVJenWjok-=gYw@mail.gmail.com>
	<CADofcAVJdqqsm45R2LTihNaVhZ4sdSJkBXEwEV7tJ8BQ+s4gRA@mail.gmail.com>
	<CANbhV-FoXqh3YWuJLoH-36Mb+gwXG4XQdSy=9x-Zv72BFGhVww@mail.gmail.com>

Simon Riggs <simon.riggs@enterprisedb.com> writes:
> On Thu, 3 Feb 2022 at 06:25, Michael Harris <harmic@gmail.com> wrote:
>> Some of these functions trigger fetching of remote resources, for
>> which a timeout is set using `alarm`. The function unfortunately does
>> not re-establish any pre-existing interval timers after it is done,
>> which leads to postgresql missing it's own expected alarm signal.
>> 
>> The reason that this was not affecting us on previous postgres
>> versions was this commit:
>> 
>> https://github.com/postgres/postgres/commit/09cf1d52267644cdbdb734294012cf1228745aaa#diff-b12a7ca3bf...
>> 
>> After this commit, once an alarm is missed, that backend never sets
>> one again, so no timeouts of any kind will work. Therefore, the
>> deadlock detector was never being run. Prior to that, the next time
>> any timeout was set by the backend it would re-establish it's timer.
>> 
>> We will of course fix our own code to prevent this issue, but I am a
>> little concerned at the above commit as it reduces the robustness of
>> postgres in this situation. Perhaps I will raise it on the
>> pgsql-hackers list.

> Hmm, so you turned off Postgres' alarms so they stopped working, and
> you're saying that is a robustness issue of Postgres?

If Michael's analysis were accurate, I'd agree that there is a robustness
issue, but I don't think there is.  See timeout.c:220:

        /*
         * Get the time remaining till the nearest pending timeout.  If it is
         * negative, assume that we somehow missed an interrupt, and force
         * signal_pending off.  This gives us a chance to recover if the
         * kernel drops a timeout request for some reason.
         */
        nearest_timeout = active_timeouts[0]->fin_time;
        if (now > nearest_timeout)
        {
            signal_pending = false;
            /* force an interrupt as soon as possible */
            secs = 0;
            usecs = 1;
        }

Now admittedly we don't have a good way to test this stanza, but
it should result in re-establishing the timer interrupt the next
time any timeout.c API is invoked after a missed interrupt.
I don't see anything more that we could or should do.  We're
not going to issue setitimer() after every user-defined function
call.

			regards, tom lane





view thread (19+ messages)  latest in thread

Message-ID: <272367.1643906187@sss.pgh.pa.us>
Permalink:  ../272367.1643906187@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/272367.1643906187@sss.pgh.pa.us

 · 

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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, simon.riggs@enterprisedb.com, harmic@gmail.com, alvherre@alvh.no-ip.org
  Subject: Re: Undetected Deadlock
  In-Reply-To: <272367.1643906187@sss.pgh.pa.us>
  References: <CADofcAWbMrvgwSMqO4iG_iD3E2v8ZUrC-_crB41my=VMM02-CA@mail.gmail.com> <202201252311.4jc4gpdzwwu7@alvherre.pgsql> <CADofcAXSn_oS3MOxS=1epiXirwETOB_BpBmM8w4=F3GaQe+cwA@mail.gmail.com> <CADofcAV29umxzTFPuJu+Cvvd5cZKkQxK0TZmpVJenWjok-=gYw@mail.gmail.com> <CADofcAVJdqqsm45R2LTihNaVhZ4sdSJkBXEwEV7tJ8BQ+s4gRA@mail.gmail.com> <CANbhV-FoXqh3YWuJLoH-36Mb+gwXG4XQdSy=9x-Zv72BFGhVww@mail.gmail.com> <272367.1643906187@sss.pgh.pa.us>

* 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