# Buggy code
async def _acquire_lock(
    self,
    conversation_id: Text,
    ticket: int,
    wait_time_in_seconds: Union[int, float],
) -> TicketLock:
    while True:
        # fetch lock in every iteration because lock might no longer exist
        lock = self.get_lock(conversation_id)

        # exit loop if lock does not exist anymore (expired)
        if not lock:
            break

        # acquire lock if it isn't locked
        if not lock.is_locked(ticket):
            return lock

        logger.debug(
            "Failed to acquire lock for conversation ID '{}'. Retrying...".format(
                conversation_id
            )
        )

        # sleep and update lock
        await asyncio.sleep(wait_time_in_seconds)
        self.update_lock(conversation_id)

    raise LockError(
        "Could not acquire lock for conversation_id '{}'.".format(conversation_id)
    )


# Traceback (rasa.core.lock_store.TicketExistsError)
rasa-production_1  | rasa.core.lock_store.TicketExistsError: Ticket '11874' already exists for conversation ID '8e001a2806b1489897accc755dd9b24f'.
rasa-production_1  | 2019-12-06 15:13:45 ERROR    rasa.core.lock_store  - Ticket could not be issued. Issuing new ticket and retrying...
rasa-production_1  | Traceback (most recent call last):
rasa-production_1  |   File "/build/lib/python3.6/site-packages/rasa/core/lock_store.py", line 109, in issue_ticket
rasa-production_1  |     self.ensure_ticket_available(lock)
rasa-production_1  |   File "/build/lib/python3.6/site-packages/rasa/core/lock_store.py", line 251, in ensure_ticket_available
rasa-production_1  |     "".format(existing_lock.last_issued, lock.conversation_id)
rasa-production_1  | rasa.core.lock_store.TicketExistsError: Ticket '11874' already exists for conversation ID '8e001a2806b1489897accc755dd9b24f'.
rasa-production_1  | 2019-12-06 15:13:45 ERROR    rasa.core.lock_store  - Ticket could not be issued. Issuing new ticket and retrying...
rasa-production_1  | Traceback (most recent call last):
rasa-production_1  |   File "/build/lib/python3.6/site-packages/rasa/core/lock_store.py", line 109, in issue_ticket
rasa-production_1  |     self.ensure_ticket_available(lock)
rasa-production_1  |   File "/build/lib/python3.6/site-packages/rasa/core/lock_store.py", line 251, in ensure_ticket_available
rasa-production_1  |     "".format(existing_lock.last_issued, lock.conversation_id)
rasa-production_1  | rasa.core.lock_store.TicketExistsError: Ticket '11874' already exists for conversation ID '8e001a2806b1489897accc755dd9b24f'.

# Fixed code
async def _acquire_lock(
    self,
    conversation_id: Text,
    ticket: int,
    wait_time_in_seconds: float,
) -> TicketLock:
    while True:
        # fetch lock in every iteration because lock might no longer exist
        lock = self.get_lock(conversation_id)

        # exit loop if lock does not exist anymore (expired)
        if not lock:
            break

        # acquire lock if it isn't locked
        if not lock.is_locked(ticket):
            return lock

        logger.debug(
            f"Failed to acquire lock for conversation ID '{conversation_id}'. "
            f"Retrying..."
        )

        # sleep and update lock
        await asyncio.sleep(wait_time_in_seconds)
        self.update_lock(conversation_id)

    raise LockError(f"Could not acquire lock for conversation_id '{conversation_id}'.")