diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 92adc4e..00b5bc5 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -10604,7 +10604,19 @@ retry:
 											  sources);
 				switched_segment = true;
 				if (readFile < 0)
+				{
+					if (!InArchiveRecovery && ArchiveRecoveryRequested)
+					{
+						InArchiveRecovery = true;
+						goto retry;
+					}
+					else if (!StandbyMode && StandbyModeRequested)
+					{
+						StandbyMode = true;
+						goto retry;
+					}
 					return false;
+				}
 			}
 		}
 	}
