Repository navigation
fix(vectorindex): close temp file fd in HnswModel.SaveToFile (#25630) - #25717
Conversation
…rigin#25630) SaveToFile created a temp file via os.CreateTemp but never closed the returned *os.File on any path, so every save leaked one file descriptor until the process hit its fd limit. Only f.Name() is ever used — usearch's Index.Save and CheckSum reopen the path themselves — so close the handle immediately after capturing the name. Also remove the temp file on every error path (close/Save/CheckSum/Destroy failures); previously the CheckSum and Destroy failures orphaned the file on disk (idx.Path is not set until success). The other two os.CreateTemp sites in model.go already close via defer, so the leak was isolated to SaveToFile. Test: TestSaveToFileNoFDLeak runs 20 save cycles with GC disabled and counts open fds via /dev/fd (portable across Linux/macOS); pre-fix the delta is exactly 20, post-fix ~0. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
…ge gate (matrixorigin#25630) The CI PR-coverage gate flagged model.go at 50% (4/8 modified lines): the added per-branch temp-file cleanups were never exercised by the happy-path TestSaveToFileNoFDLeak. Refactor SaveToFile's cleanup to a single deferred os.Remove (removed unless idx.Path was set to fpath on success), which both simplifies the four per-error-branch os.Remove calls into one and makes the cleanup reachable from a test. Make the checksum call injectable (saveToFileCheckSum var) so a test can force a mid-save failure deterministically. Add TestSaveToFileCleanupOnError: stub the checksum to fail, then assert SaveToFile propagates the error, leaves idx.Path unset, and removes the temp file (no orphan). Modified-line coverage of the change is now 100%. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed the complete diff and the SaveToFile resource lifecycle. The temp-file descriptor is closed before pathname-based Save/CheckSum, failure paths retain a single local cleanup owner, and ownership transfers to idx.Path only after Save, checksum, and index destruction succeed. Targeted tests, targeted race tests, the full HNSW package, go vet, and go build pass on the current head. No correctness, leak, hang, unbounded-growth, or compatibility blocker found.
Merge Queue Status
This pull request spent 9 minutes 29 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #25717 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
Failing checks:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
…rigin#25630) (matrixorigin#25717) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#25630 ## What this PR does / why we need it: SaveToFile created a temp file via os.CreateTemp but never closed the returned *os.File on any path, so every save leaked one file descriptor until the process hit its fd limit. Only f.Name() is ever used — usearch's Index.Save and CheckSum reopen the path themselves — so close the handle immediately after capturing the name. Also remove the temp file on every error path (close/Save/CheckSum/Destroy failures); previously the CheckSum and Destroy failures orphaned the file on disk (idx.Path is not set until success). The other two os.CreateTemp sites in model.go already close via defer, so the leak was isolated to SaveToFile. Test: TestSaveToFileNoFDLeak runs 20 save cycles with GC disabled and counts open fds via /dev/fd (portable across Linux/macOS); pre-fix the delta is exactly 20, post-fix ~0. --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…rigin#25630) (matrixorigin#25717) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#25630 ## What this PR does / why we need it: SaveToFile created a temp file via os.CreateTemp but never closed the returned *os.File on any path, so every save leaked one file descriptor until the process hit its fd limit. Only f.Name() is ever used — usearch's Index.Save and CheckSum reopen the path themselves — so close the handle immediately after capturing the name. Also remove the temp file on every error path (close/Save/CheckSum/Destroy failures); previously the CheckSum and Destroy failures orphaned the file on disk (idx.Path is not set until success). The other two os.CreateTemp sites in model.go already close via defer, so the leak was isolated to SaveToFile. Test: TestSaveToFileNoFDLeak runs 20 save cycles with GC disabled and counts open fds via /dev/fd (portable across Linux/macOS); pre-fix the delta is exactly 20, post-fix ~0. --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…rigin#25630) (matrixorigin#25717) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#25630 ## What this PR does / why we need it: SaveToFile created a temp file via os.CreateTemp but never closed the returned *os.File on any path, so every save leaked one file descriptor until the process hit its fd limit. Only f.Name() is ever used — usearch's Index.Save and CheckSum reopen the path themselves — so close the handle immediately after capturing the name. Also remove the temp file on every error path (close/Save/CheckSum/Destroy failures); previously the CheckSum and Destroy failures orphaned the file on disk (idx.Path is not set until success). The other two os.CreateTemp sites in model.go already close via defer, so the leak was isolated to SaveToFile. Test: TestSaveToFileNoFDLeak runs 20 save cycles with GC disabled and counts open fds via /dev/fd (portable across Linux/macOS); pre-fix the delta is exactly 20, post-fix ~0. --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
issue #25630
What this PR does / why we need it:
SaveToFile created a temp file via os.CreateTemp but never closed the returned *os.File on any path, so every save leaked one file descriptor until the process hit its fd limit. Only f.Name() is ever used — usearch's Index.Save and CheckSum reopen the path themselves — so close the handle immediately after capturing the name. Also remove the temp file on every error path (close/Save/CheckSum/Destroy failures); previously the CheckSum and Destroy failures orphaned the file on disk (idx.Path is not set until success). The other two os.CreateTemp sites in model.go already close via defer, so the leak was isolated to SaveToFile.
Test: TestSaveToFileNoFDLeak runs 20 save cycles with GC disabled and counts open fds via /dev/fd (portable across Linux/macOS); pre-fix the delta is exactly 20, post-fix ~0.