Skip to content

fix(vectorindex): close temp file fd in HnswModel.SaveToFile (#25630) - #25717

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
cpegeric:issue_25630
Jul 14, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
cpegeric:issue_25630

Conversation

@cpegeric

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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.

…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-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

…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]>
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 14, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mergify mergify Bot added the queued label Jul 14, 2026
@mergify

mergify Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-14 14:20 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-14 14:30 UTC · at 2f6fb4f667095b63ef6490f127a5ca829cca4543

This pull request spent 9 minutes 29 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]

Reason

Pull 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.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You 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.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 6b2f87c into matrixorigin:main Jul 14, 2026
23 of 24 checks passed
@mergify mergify Bot added dequeued and removed queued labels Jul 14, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants