fix: close local lock file on failure - #1241
Conversation
✅ Deploy Preview for poetic-froyo-8baba7 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughBoth Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
eeshsaxena
left a comment
There was a problem hiding this comment.
Confirmed this is a genuine handle leak: in _load, self._flock_file = open(lock_file_path, "r+") runs before portalocker.lock(...), and the old except portalocker.exceptions.LockException raised RuntimeError without ever closing that handle - so the lock file object leaks until GC (relevant on Windows especially, since this is exactly the "folder already locked by another instance" path). Closing it and nulling self._flock_file before raising is correct, and adding the broad except Exception: ... raise to clean up on any other failure is a nice touch.
One small suggestion: #1264 is an almost identical fix for the same lines, and it additionally does raise RuntimeError(...) from None, which suppresses the "During handling of the above exception" chaining and reads a bit cleaner for this user-facing message. Might be worth adding here (or the maintainers may want to consolidate the two PRs).
Solid fix otherwise. Deferring to the maintainers.
Closes #1234.
Summary
.lockfile whenportalocker.lock()fails inQdrantLocalAsyncQdrantLocalRoot cause
The local client opens the
.lockfile before acquiring the portalocker lock. If lock acquisition raises, the constructor raises without closing the opened file handle.Validation
origin/master: monkeypatchedportalocker.lock()to raiseLockException; captured.lockfile remained open (closed: False)uv run --with numpy --with pydantic --with portalocker --with grpcio --with protobuf --with urllib3 --with 'httpx[http2]' --with pytest pytest tests/test_qdrant_client.py::test_local_lock_failure_closes_lock_file -q->2 passed\n-uv run --with 'ruff==0.4.3' ruff check qdrant_client/local/qdrant_local.py qdrant_client/local/async_qdrant_local.py->All checks passed\n\nNote: running ruff across the full touched test file also reports an existing unrelatedF841intests/test_qdrant_client.pyonorigin/master(except Exception as ex), so I kept the lint check scoped to the changed local implementation files.