Skip to content

Local storage retains its thread lock after IPC acquisition fails #2202

Open

Description

@zhechen-cs

Summary

LockLocalStorage.__enter__() leaves its thread lock acquired if the IPC lock times out or raises an exception. Since a failed __enter__ does not call __exit__, reusing the same lock object cannot acquire the thread lock again, even after the IPC contention is gone.

Detailed Information

Reproduced on current trunk (bd9cbb3e393bc42f57684481e7c62e9293007584), Python 3.12/macOS. This deterministic reproducer models the documented false return from fasteners.InterProcessLock.acquire() when its timeout expires:

import os
import tempfile
from unittest.mock import patch
from libcloud.storage.drivers.local import LockLocalStorage
from libcloud.common.types import LibcloudError

with tempfile.TemporaryDirectory() as root:
    lock = LockLocalStorage(os.path.join(root, "object"))
    with patch.object(lock.ipc_lock, "acquire", return_value=False):
        try:
            lock.__enter__()
        except LibcloudError:
            pass
    print(lock.thread_lock.locked())  # True

The thread lock should be released before propagating acquisition failure. The same leak occurs if IPC acquisition raises OSError or is interrupted by KeyboardInterrupt.

This is separate from #1975 / #2172, which address leftover lock files after a successful acquisition.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions