- // Bring the connection up
- final ConnectedClientConnection<T> newConn = connectionUp(conn, backend);
+ // Create a new connected connection
+ final ConnectedClientConnection<T> newConn = new ConnectedClientConnection<>(conn.context(),
+ conn.cookie(), backend);
+ LOG.debug("{}: resolving connection {} to {}", persistenceId(), conn, newConn);
+
+ // Start reconnecting without the old connection lock held
+ final ConnectionConnectCohort cohort = Verify.verifyNotNull(connectionUp(newConn));
+
+ // Lock the old connection and get a reference to its entries
+ final Iterable<ConnectionEntry> replayIterable = conn.startReplay();
+
+ // Finish the connection attempt
+ final ReconnectForwarder forwarder = Verify.verifyNotNull(cohort.finishReconnect(replayIterable));
+
+ // Install the forwarder, unlocking the old connection
+ conn.finishReplay(forwarder);