Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgzf::Reader::set_thread_pool causes the bgzf Reader to hang if the thread pool goes out of scope #371

Open
ThomasHickman opened this issue Dec 7, 2022 · 0 comments

Comments

@ThomasHickman
Copy link

If you run this:

use rust_htslib::*;
use std::io::Read;

fn get_reader() -> bgzf::Reader {
    let mut reader = bgzf::Reader::from_path("test-file.vcf.gz").unwrap();
    let thread_pool = tpool::ThreadPool::new(4).unwrap();
    reader.set_thread_pool(&thread_pool).unwrap();
    reader
}

fn main() {
    let mut buffer = Vec::new();
    let mut reader = get_reader();

    reader.read_to_end(&mut buffer).unwrap();
    println!("{}", buffer.len());
}

The resultant executable will hang. This seems to be caused by fact that the thread_pool goes out of scope, as can be seen by the fact that this snippet does not hang:

use rust_htslib::*;
use std::io::Read;

fn main() {
    let mut buffer = Vec::new();
    let mut reader = bgzf::Reader::from_path("test-file.vcf.gz").unwrap();
    let thread_pool = tpool::ThreadPool::new(4).unwrap();
    reader.set_thread_pool(&thread_pool).unwrap();

    reader.read_to_end(&mut buffer).unwrap();
    println!("{}", buffer.len());
}

The cause of this seems to be that bgzf::Reader::set_thread_pool does not keep a reference to the underlying thread_pool handle as it should do according to the documentation of ThreadPool (see https://docs.rs/rust-htslib/latest/rust_htslib/tpool/struct.ThreadPool.html) and as the bgzf::Writer::set_thread_pool method does (see https://github.com/rust-bio/rust-htslib/blob/master/src/bgzf/mod.rs#L244)

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

No branches or pull requests

1 participant