Merge branch 'stable-3.8' into stable-3.9

* stable-3.8:
  Remove events from beforeStartupEventsQueue in-memory queue

Change-Id: Ib9130c9b1e1c84b41d802a4525e428191e7a0848
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueue.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueue.java
index 31057ca..8fb6b0d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueue.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueue.java
@@ -763,7 +763,8 @@
 
   private void fireBeforeStartupEvents() {
     Set<String> eventsReplayed = new HashSet<>();
-    for (ReferenceBatchUpdatedEvent event : beforeStartupEventsQueue) {
+    ReferenceBatchUpdatedEvent event;
+    while ((event = beforeStartupEventsQueue.poll()) != null) {
       String eventKey =
           String.format(
               "%s:%s",