defect_fix.patch

text/x-patch

Filename: defect_fix.patch
Type: text/x-patch
Part: 0
Message: Re: Race condition in FetchTableStates() breaks synchronization of subscription tables

Patch

Format: unified
File+
src/backend/replication/logical/tablesync.c 4 4
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 4207b9356c..92eb86a249 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -123,7 +123,7 @@
 #include "utils/syscache.h"
 #include "utils/usercontext.h"
 
-static bool table_states_valid = false;
+static unsigned int table_states_invalid = 1;
 static List *table_states_not_ready = NIL;
 static bool FetchTableStates(bool *started_tx);
 
@@ -273,7 +273,7 @@ wait_for_worker_state_change(char expected_state)
 void
 invalidate_syncing_table_states(Datum arg, int cacheid, uint32 hashvalue)
 {
-	table_states_valid = false;
+	table_states_invalid++;
 }
 
 /*
@@ -1568,7 +1568,7 @@ FetchTableStates(bool *started_tx)
 
 	*started_tx = false;
 
-	if (!table_states_valid)
+	if (table_states_invalid)
 	{
 		MemoryContext oldctx;
 		List	   *rstates;
@@ -1608,7 +1608,7 @@ FetchTableStates(bool *started_tx)
 		has_subrels = (table_states_not_ready != NIL) ||
 			HasSubscriptionRelations(MySubscription->oid);
 
-		table_states_valid = true;
+		table_states_invalid--;
 	}
 
 	return has_subrels;