Skip to content

fix(datasets): parse CMIP ingest in processes so --n-jobs > 1 is safe#796

Merged
lewisjared merged 2 commits into
mainfrom
fix/cmip-ingest-parallel-process-pool
Jul 8, 2026
Merged

fix(datasets): parse CMIP ingest in processes so --n-jobs > 1 is safe#796
lewisjared merged 2 commits into
mainfrom
fix/cmip-ingest-parallel-process-pool

Conversation

@lewisjared

@lewisjared lewisjared commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Problem

ref datasets ingest --n-jobs > 1 reliably crashes the interpreter (SIGSEGV) with the default complete CMIP6 parser.

Catalog parsing fanned files across a ThreadPoolExecutor, but the netCDF4/HDF5 wheels published on PyPI are built without --enable-threadsafe. The complete parser opens every file with netCDF4.Dataset(...), so parsing across threads opened HDF5 files concurrently and corrupted HDF5's global state.

Fix

Parsing now runs in worker processes via ProcessPoolExecutor using the spawn start method (matching LocalExecutor). Then each open is single-threaded, but parallel.

On a fast local filesystem the parallism isn't worth the overhead of setting up the process pool, but for parallel filesystems such as Lustere or NFS the parallisation helps.

Tests

New TestParallelParsingSafety in test_catalog_builder.py:

  • proves parsing runs out-of-process (PID check — would fail under the old threads),
  • runs the real file-opening complete parser in parallel over genuine HDF5 files and asserts no crash + correctness,
  • asserts parallel output matches sequential.

Shared picklable stub parsers moved into conftest_plugin so spawn/forkserver workers can re-import them.

Not covered

Behaviour on an HDF5 build compiled with --enable-threadsafe (processes are safe there too, just not the failure mode being fixed). Maybe that is useful for some HPCs, but I deferred this until we have a request.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@lewisjared, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 13 seconds

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 812a4128-43e8-495b-947d-30d0c407ff40

📥 Commits

Reviewing files that changed from the base of the PR and between ee69ce0 and 806d488.

📒 Files selected for processing (4)
  • changelog/796.fix.md
  • packages/climate-ref/src/climate_ref/conftest_plugin.py
  • packages/climate-ref/src/climate_ref/datasets/catalog_builder.py
  • packages/climate-ref/tests/unit/datasets/test_catalog_builder.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cmip-ingest-parallel-process-pool

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Catalog parsing fanned files across a ThreadPoolExecutor, but the netCDF4/HDF5
wheels published on PyPI are built without --enable-threadsafe. The default
`complete` CMIP6 parser opens every file, so `ref datasets ingest --n-jobs > 1`
opened HDF5 files from multiple threads concurrently and reliably crashed the
interpreter with SIGSEGV/SIGBUS.

Parsing now runs in worker processes via ProcessPoolExecutor using the "spawn"
start method (matching the LocalExecutor). Each interpreter opens files
single-threaded, which is safe, and sidesteps the GIL so I/O-bound parsing
scales across a parallel filesystem. Worker count is capped at the file count
and -1 still means all CPUs.

Shared picklable stub parsers moved into conftest_plugin so spawn/forkserver
workers can re-import them; added regression tests that prove parsing runs
out-of-process and that the file-opening complete parser survives parallel
parsing and matches sequential output.

Constraint: netCDF4/HDF5 PyPI wheels are not thread-safe (no --enable-threadsafe)
Rejected: ThreadPoolExecutor | segfaults on concurrent HDF5 opens
Rejected: forkserver default | inconsistent with LocalExecutor's spawn choice
Confidence: high
Scope-risk: narrow
Not-tested: behaviour on an HDF5 build compiled with --enable-threadsafe
@lewisjared lewisjared force-pushed the fix/cmip-ingest-parallel-process-pool branch from 5bd6d46 to 9e0ae24 Compare July 8, 2026 02:09
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
core 92.47% <100.00%> (+0.02%) ⬆️
providers 86.97% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...te-ref/src/climate_ref/datasets/catalog_builder.py 96.22% <100.00%> (+0.18%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lewisjared lewisjared merged commit 35985fb into main Jul 8, 2026
28 checks passed
@lewisjared lewisjared deleted the fix/cmip-ingest-parallel-process-pool branch July 8, 2026 04:10
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.

1 participant