bam reader won't close files and cause 'too many open files' error.
y9c opened this issue · comments
I tried to use rust-htslib to parse multiple regions in parallel. The bam files are read within a function call and the function is mapped into a .par_iter()
chain. I expect the bam files are closed automatically after each loop. However, htslib keep opening new files and cause a too many open files
error.
The code are within this repo:
https://github.com/y9c/mpileup/blob/12d8a589676c1d773425de0987666c29b4430394/src/base.rs#L426-L441
And the bug and be trigger by the following example.
cargo run base -t ./test/large_region.bed -r ./test/reference.fa -i test/sample1.bam test/sample2.bam > /dev/null
I am not sure if I am using htslib in a wrong way. Could you help me with this? Thank you.