aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2017-04-20 23:12:57 +0900
committerFujii Masao <fujii@postgresql.org>2017-04-20 23:12:57 +0900
commit8bbc618b4825b13a9776f2289acd06483e140300 (patch)
tree1765ae9ba5a7b00a8f593f50473a4920f467302a
parente68432a0e1ad07b6848fc9bbc11e382eb43b8618 (diff)
downloadpostgresql-8bbc618b4825b13a9776f2289acd06483e140300.tar.gz
postgresql-8bbc618b4825b13a9776f2289acd06483e140300.zip
Don't call the function that may raise an error while holding spinlock.
It's not safe to raise an error while holding spinlock. But previously logical replication worker for table sync called the function which reads the system catalog and may raise an error while it's holding spinlock. Which could lead to the trouble where spinlock will never be released and the server gets stuck infinitely. Author: Petr Jelinek Reviewed-by: Kyotaro Horiguchi and Fujii Masao Reported-by: Fujii Masao Discussion: http://postgr.es/m/CAHGQGwFDWh_Qr-q_GEMpD+qH=vYPMdVqw=ZOSY3kX_Pna9R9SA@mail.gmail.com
-rw-r--r--src/backend/replication/logical/tablesync.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 108326bef1c..b4b48d92cf4 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -705,17 +705,20 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
{
char *slotname;
char *err;
+ char relstate;
+ XLogRecPtr relstate_lsn;
/* Check the state of the table synchronization. */
StartTransactionCommand();
+ relstate = GetSubscriptionRelState(MyLogicalRepWorker->subid,
+ MyLogicalRepWorker->relid,
+ &relstate_lsn, false);
+ CommitTransactionCommand();
+
SpinLockAcquire(&MyLogicalRepWorker->relmutex);
- MyLogicalRepWorker->relstate =
- GetSubscriptionRelState(MyLogicalRepWorker->subid,
- MyLogicalRepWorker->relid,
- &MyLogicalRepWorker->relstate_lsn,
- false);
+ MyLogicalRepWorker->relstate = relstate;
+ MyLogicalRepWorker->relstate_lsn = relstate_lsn;
SpinLockRelease(&MyLogicalRepWorker->relmutex);
- CommitTransactionCommand();
/*
* To build a slot name for the sync work, we are limited to NAMEDATALEN -