while (true)
    {
        XLogSegNo   segno;
+       XLogRecPtr  restart_lsn;
 
        /*
         * For logical slots log a standby snapshot and start logical decoding
            XLogRecPtr  flushptr;
 
            /* start at current insert position */
+           restart_lsn = GetXLogInsertRecPtr();
            SpinLockAcquire(&slot->mutex);
-           slot->data.restart_lsn = GetXLogInsertRecPtr();
+           slot->data.restart_lsn = restart_lsn;
            SpinLockRelease(&slot->mutex);
 
            /* make sure we have enough information to start */
        }
        else
        {
+           restart_lsn = GetRedoRecPtr();
            SpinLockAcquire(&slot->mutex);
-           slot->data.restart_lsn = GetRedoRecPtr();
+           slot->data.restart_lsn = restart_lsn;
            SpinLockRelease(&slot->mutex);
        }