Skip to content

Fix several lock, async, exception-handling and counting bugs (+ tests) - #63

Merged
awolverp merged 8 commits into
mainfrom
patch
Aug 1, 2026
Merged

Fix several lock, async, exception-handling and counting bugs (+ tests)#63
awolverp merged 8 commits into
mainfrom
patch

Conversation

@awolverp

@awolverp awolverp commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Fixed several bugs related to miss counting, missing await, lock cleanup on exceptions, and cancellation handling.

What was fixed

  • Miss counter when lock is disabled
    With lock=False, misses were never incremented and hits were double-counted. Now they are counted correctly.

  • Missing await on the ignore path
    In the async wrapper, when cachebox__ignore=True and lock was off, the function was not awaited and a coroutine object was returned. Now it is properly awaited.

  • Lock leak when the function raises
    If the cached function raised an exception, the per-key lock was never removed and stayed in memory. It is now cleaned up properly.

  • Waiters not decremented on cancellation
    If a task was cancelled while waiting for the lock, the waiter count stayed high and the lock was never cleaned up. Now it is decremented with try/finally.

  • BaseException handling
    All exceptions now go through the same cleanup path (previously only Exceptions was caught).

  • Frozen validation
    The check for the underlying cache no longer relies on assert (so it still works with -O).

  • make_key
    Removed an unreachable branch.

@awolverp
awolverp merged commit 1b3b98a into main Aug 1, 2026
12 checks passed
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