diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index 9b2137a..6998bb8 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -590,6 +590,10 @@ SyncRepGetSyncStandbys(bool *am_sync)
 		if (XLogRecPtrIsInvalid(walsnd->flush))
 			continue;
 
+		/* Notify myself as 'synchonized' if I am */
+		if (am_sync != NULL && walsnd == MyWalSnd)
+			*am_sync = true;
+
 		/*
 		 * If the priority is equal to 1, consider this standby as sync
 		 * and append it to the result. Otherwise append this standby
@@ -598,8 +602,6 @@ SyncRepGetSyncStandbys(bool *am_sync)
 		if (this_priority == 1)
 		{
 			result = lappend_int(result, i);
-			if (am_sync != NULL && walsnd == MyWalSnd)
-				*am_sync = true;
 			if (list_length(result) == SyncRepConfig->num_sync)
 			{
 				list_free(pending);
@@ -630,9 +632,6 @@ SyncRepGetSyncStandbys(bool *am_sync)
 	{
 		bool		needfree = (result != NIL && pending != NIL);
 
-		if (am_sync != NULL && !(*am_sync))
-			*am_sync = list_member_int(pending, MyWalSnd->slotno);
-
 		result = list_concat(result, pending);
 		if (needfree)
 			pfree(pending);
@@ -640,6 +639,13 @@ SyncRepGetSyncStandbys(bool *am_sync)
 	}
 
 	/*
+	 * The pending list contains eventually potentially-synchronized standbys
+	 * and this walsender may be one of them. So once reset am_sync.
+	 */
+	if (am_sync != NULL)
+		*am_sync = false;
+
+	/*
 	 * Find the sync standbys from the pending list.
 	 */
 	priority = next_highest_priority;
