Skip to content

Fix deadlock due to non-reentrant lock pool - #1312

Merged
edwinyyyu merged 1 commit into
MemMachine:mainfrom
edwinyyyu:fix_rwlock_deadlock
Apr 9, 2026
Merged

edwinyyyu merged 1 commit into
MemMachine:mainfrom
edwinyyyu:fix_rwlock_deadlock

Conversation

@edwinyyyu

@edwinyyyu edwinyyyu commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Purpose of the change

Non-reentrant lock pool will deadlock due to hash collisions.

Hash collisions occur with 100% guarantee as soon as number of keys exceeds the pool size (by default a tiny 128) by pigeonhole principle.

Even worse, it takes only 14 keys for collision probability to be greater than 50%. See https://en.wikipedia.org/wiki/Birthday_problem

Description

Remove non-reentrant lock pool. Dict of locks is small for even tens of thousands of locks.

Fixes/Closes

Fixes #1303

Type of change

[Please delete options that are not relevant.]

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g., code style improvements, linting)
  • Documentation update
  • Project Maintenance (updates to build scripts, CI, etc., that do not affect the main project)
  • Security (improves security without changing functionality)

How Has This Been Tested?

  • Unit Test
  • Integration Test
  • End-to-end Test
  • Test Script (please provide)
  • Manual verification (list step-by-step instructions)

Checklist

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • Confirmed all checks passed
  • Contributor has signed the commit(s)
  • Reviewed the code
  • Run, Tested, and Verified the change(s) work as expected

@edwinyyyu
edwinyyyu requested a review from jealous April 8, 2026 18:19
@edwinyyyu edwinyyyu added this to the v0.3.4 milestone Apr 8, 2026
@edwinyyyu
edwinyyyu force-pushed the fix_rwlock_deadlock branch from 9d46337 to 711e857 Compare April 8, 2026 18:26
@edwinyyyu edwinyyyu changed the title Remove non-reentrant lock pool Fix deadlock due to non-reentrant lock pool Apr 8, 2026
@edwinyyyu
edwinyyyu merged commit fe2790d into MemMachine:main Apr 9, 2026
44 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.

[Bug]: Deadlock in rwlock pool

3 participants