Skip to content

chroma: use force_fpcalc=True to prevent fd exhaustion - #6928

Open
slmingol wants to merge 2 commits into
beetbox:masterfrom
slmingol:fix/chroma-fd-leak-force-fpcalc
Open

chroma: use force_fpcalc=True to prevent fd exhaustion#6928
slmingol wants to merge 2 commits into
beetbox:masterfrom
slmingol:fix/chroma-fd-leak-force-fpcalc

Conversation

@slmingol

Copy link
Copy Markdown

Problem

The chroma plugin leaks file descriptors when fingerprinting via audioread's GStreamer backend. When fingerprinting fails or GStreamer encounters an error, the pipeline socket is left open. Across thousands of files this exhausts the process fd limit:

```
OSError: [Errno 24] No file descriptors available
```

This causes `beet import` to crash mid-run on large libraries. Raising `ulimit -n` only delays the inevitable — the leak is unbounded.

Reported in #5171.

Fix

`pyacoustid.fingerprint_file()` accepts a `force_fpcalc=True` parameter (added in pyacoustid 1.2.0) that routes fingerprinting through the `fpcalc` binary, bypassing audioread and GStreamer entirely. `fpcalc` is already a hard dependency of the chroma plugin, so no new requirements are introduced.

Both call sites in `chroma.py` are updated.

Testing

Verified against a library of ~10,000 albums where the previous code consistently crashed with fd exhaustion. With `force_fpcalc=True` the import runs to completion.

@slmingol
slmingol requested a review from a team as a code owner August 14, 2026 01:08
Copilot AI lite review requested due to automatic review settings August 14, 2026 01:08
@github-actions github-actions Bot added the chroma chroma plugin label Aug 14, 2026
@github-actions

Copy link
Copy Markdown

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

Copilot AI 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.

Pull request overview

grug see PR try fix fd leak in chroma fingerprint by skip audioread/GStreamer path and always go through fpcalc via force_fpcalc=True. this fit beetsplug/chroma.py fingerprint + acoustid lookup path.

Changes:

  • pass force_fpcalc=True in acoustid_match() fingerprint generation
  • pass force_fpcalc=True in fingerprint_item() fingerprint generation
Suppressed comments (1)

beetsplug/chroma.py:445

  • grug see new force_fpcalc kwarg here too. if pyacoustid old, TypeError bubble up and crash fingerprint command/import. grug want catch TypeError and print upgrade hint.
            _, fp = acoustid.fingerprint_file(util.syspath(item.path), force_fpcalc=True)

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread beetsplug/chroma.py Outdated
"""
try:
duration, fp = acoustid.fingerprint_file(util.syspath(path))
duration, fp = acoustid.fingerprint_file(util.syspath(path), force_fpcalc=True)
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.96%. Comparing base (b7993d1) to head (b7728b6).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6928      +/-   ##
==========================================
+ Coverage   75.88%   75.96%   +0.07%     
==========================================
  Files         164      164              
  Lines       21448    21448              
  Branches     3381     3381              
==========================================
+ Hits        16275    16292      +17     
+ Misses       4369     4351      -18     
- Partials      804      805       +1     
Files with missing lines Coverage Δ
beetsplug/chroma.py 53.73% <100.00%> (+7.08%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@slmingol
slmingol force-pushed the fix/chroma-fd-leak-force-fpcalc branch 2 times, most recently from 2750b67 to 686d29a Compare August 16, 2026 05:07
slmingol and others added 2 commits August 16, 2026 09:02
audioread's GStreamer backend leaks file descriptors when fingerprinting
fails or GStreamer encounters an error. Across thousands of files this
exhausts the process fd limit:

    OSError: [Errno 24] No file descriptors available

pyacoustid.fingerprint_file() accepts force_fpcalc=True (added in
pyacoustid 1.2.0) which routes fingerprinting through the fpcalc binary,
bypassing audioread/GStreamer entirely. fpcalc is already a hard dependency
of the chroma plugin so no new requirements are introduced.

Both call sites are updated. A TypeError guard is added at each site to
handle pyacoustid versions older than 1.2.0 that do not accept the kwarg.

Fixes beetbox#5171

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add TestAcoustidMatch:
- assert force_fpcalc=True is passed to fingerprint_file
- assert TypeError from old pyacoustid is caught, not raised

Add TestFingerprintItem:
- assert TypeError from old pyacoustid in fingerprint_item returns None

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@slmingol
slmingol force-pushed the fix/chroma-fd-leak-force-fpcalc branch from 686d29a to b7728b6 Compare August 16, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chroma chroma plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants