diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index b4b48d9..30da0fb 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -351,7 +351,7 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
 			 * There is a worker synchronizing the relation and waiting for
 			 * apply to do something.
 			 */
-			if (syncworker && rstate->state == SUBREL_STATE_SYNCWAIT)
+			if (syncworker && syncworker->relstate == SUBREL_STATE_SYNCWAIT)
 			{
 				/*
 				 * There are three possible synchronization situations here.
