Repository navigation
fix(cram): give reader threads enough stack for CRAM 3.1 rANS-Nx16 - #220
Merged
Merged
Conversation
noodles' rANS-Nx16 decoder overflows Rust's 2 MiB default thread stack. samtools writes CRAM 3.1 with that codec by default, so any such file crashed RustQC with --threads above 1 (the main thread has 8 MiB, so single-threaded runs worked). Both rayon pools now use 8 MiB stacks. Adds a 3 KB CRAM 3.1 fixture of tests/data/test.bam and a test that runs it at 1 and 4 threads and checks flagstat against the BAM. Fixes #151 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #151. On main, any CRAM 3.1 file that samtools writes with its default settings crashes RustQC with
fatal runtime error: stack overflowwhen--threadsis above 1.Cause
samtools' default CRAM 3.1 profile compresses most data series with rANS-Nx16 (
rNx16insamtools cram-size). noodles' rANS-Nx16 decoder needs more than the 2 MiB stack Rust gives a new thread, and RustQC reads alignments on rayon worker threads. With--threads 1it reads on the main thread, which has 8 MiB, so single-threaded runs worked. CRAM 3.0, and CRAM 3.1 at samtools' archive level (which uses the arithmetic coder instead), decode fine.Fix
Both rayon pools (per-chromosome workers in
counting.rs, per-file workers inmain.rs) now use an 8 MiB stack, set byrna::bam::READER_THREAD_STACK_SIZE. 4 MiB was already enough for the files I tried; 8 MiB matches the main thread.Testing
tests/data/cram31/:tests/data/test.bamwritten as CRAM 3.1 with samtools 1.21 defaults (3 KB). The README there has the commands.cargo fmt --check,cargo clippy -- -D warningsandcargo test --releasepass.The error in #151 came from htslib in v0.2.1 (
Slice decode failure). With noodles, that file would most likely have hit this crash instead, so the reporter should retry with v0.3.0.🤖 Generated with Claude Code