[HACKERS] libpqrcv_PQexec() seems to violate latch protocol - Mailing list pgsql-hackers

From Andres Freund
Subject [HACKERS] libpqrcv_PQexec() seems to violate latch protocol
Date
Msg-id 20170606210405.sim3yl6vpudhmufo@alap3.anarazel.de
Whole thread Raw
Responses Re: [HACKERS] libpqrcv_PQexec() seems to violate latch protocol  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

The function  in $subject does:       while (PQisBusy(streamConn))       {           int         rc;
           /*            * We don't need to break down the sleep into smaller increments,            * since we'll get
interruptedby signals and can either handle            * interrupts here or elog(FATAL) within SIGTERM signal handler
if           * the signal arrives in the middle of establishment of            * replication connection.            */
        ResetLatch(&MyProc->procLatch);           rc = WaitLatchOrSocket(&MyProc->procLatch,
     WL_POSTMASTER_DEATH | WL_SOCKET_READABLE |                                  WL_LATCH_SET,
       PQsocket(streamConn),                                  0,
WAIT_EVENT_LIBPQWALRECEIVER);          if (rc & WL_POSTMASTER_DEATH)               exit(1);           /* interrupted */
         if (rc & WL_LATCH_SET)           {               CHECK_FOR_INTERRUPTS();               continue;           }
 

Doing ResetLatch();WaitLatch() like that makes it possible to miss a the
latch being set, e.g. if it happens just after WaitLatchOrSocket()
returns.

Afaict, the ResetLatch() really should just instead be in the if (rc & WL_LATCH_SET)
block.

Unless somebody protests, I'll make it so.

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Kevin Grittner
Date:
Subject: Re: [HACKERS] PG10 transition tables, wCTEs and multiple operationson the same table
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] libpqrcv_PQexec() seems to violate latch protocol