Visitar URL original
🐛 fix(async): invoke _poll_delay during contended polling by feiiiiii5 · Pull Request #928 · tox-dev/filelock · GitHub
Skip to content

🐛 fix(async): invoke _poll_delay during contended polling - #928

Open
feiiiiii5 wants to merge 2 commits into
tox-dev:mainfrom
feiiiiii5:fix/async-poll-delay
Open

feiiiiii5 wants to merge 2 commits into
tox-dev:mainfrom
feiiiiii5:fix/async-poll-delay

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Problem

In BaseFileLock, contended lock acquisitions track an attempt counter and call self._poll_delay(poll_interval, attempt) to compute the retry delay (supporting exponential backoff, jitter, and subclass custom backoff hooks).

However, in BaseAsyncFileLock._async_poll_until_acquired (src/filelock/asyncio.py), the attempt counter was omitted and the delay was hardcoded as delay = poll_interval. As a result:

  • Async locks (such as AsyncStrictSoftFileLock) and custom subclasses overriding _poll_delay never invoked _poll_delay during contended polling.
  • The contention backoff behavior diverged between synchronous and asynchronous lock implementations.

Solution

  1. Initialize attempt = 0 prior to the acquisition poll loop in BaseAsyncFileLock._async_poll_until_acquired.
  2. Increment attempt += 1 on each retry attempt and pass it to self._poll_delay(poll_interval, attempt), mirroring BaseFileLock._poll_until_acquired.
  3. Add regression test test_poll_contention_invokes_poll_delay in tests/test_async_filelock.py.
  4. Include towncrier news fragment docs/changelog/+async-poll-delay.bugfix.rst.

Verification

  • Confirmed failing test on base commit (AssertionError: BaseAsyncFileLock failed to call _poll_delay!).
  • Ran full test_async_filelock.py suite (242 tests passing).
  • Verified ruff check and ruff format --check pass cleanly.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant