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

HTTPS responses hang trying to flush writer #144

Closed
evetsso opened this issue Apr 22, 2018 · 3 comments · Fixed by #151
Closed

HTTPS responses hang trying to flush writer #144

evetsso opened this issue Apr 22, 2018 · 3 comments · Fixed by #151
Labels

Comments

@evetsso
Copy link

evetsso commented Apr 22, 2018

I'm pretty new to rust, but trying to use tiny_http to implement a simple web server app over https as a learning exercise.

I've turned on the ssl feature in Cargo.toml:

[dependencies.tiny_http]
version = "0.6.0"
features = ["ssl"]

And working with a cut down version of the example ssl.rs:

extern crate tiny_http;

fn main() {
    use tiny_http::{Server, Response};

    let server = Server::https("0.0.0.0:8000", tiny_http::SslConfig {
        certificate: include_bytes!("cert.pem").to_vec(),
        private_key: include_bytes!("key.pem").to_vec(),
    }).unwrap();

    for request in server.incoming_requests() {
        assert!(request.secure());

        println!("received request! method: {:?}, url: {:?}, headers: {:?}",
            request.method(),
            request.url(),
            request.headers()
        );

        let response = Response::from_string("hello world");
        let _ = request.respond(response);
    }
}

Builds and runs fine, but trying a request with wget --no-check-certificate https://localhost:8000/ results in the connection being established, the request being sent, but wget hangs trying to get a response back.

Attaching gdb to the tiny_http process shows it's hung trying to flush the writer:

#0  0x00007f9f67f0d73c in __lll_lock_wait () from /usr/lib/libpthread.so.0
#1  0x00007f9f67f06a55 in pthread_mutex_lock () from /usr/lib/libpthread.so.0
#2  0x000055cb827e37a2 in std::sys::unix::mutex::Mutex::lock (self=0x7f9f66e0f390)
    at /build/rust/src/rustc-1.25.0-src/src/libstd/sys/unix/mutex.rs:67
#3  0x000055cb82810525 in std::sys_common::mutex::Mutex::lock (self=0x7f9f66e0f390)
    at /build/rust/src/rustc-1.25.0-src/src/libstd/sys_common/mutex.rs:40
#4  0x000055cb827ee7e6 in <std::sync::mutex::Mutex<T>>::lock (self=0x7f9f66e0f5b0)
    at /build/rust/src/rustc-1.25.0-src/src/libstd/sync/mutex.rs:230
#5  0x000055cb8281ba14 in <tiny_http::util::refined_tcp_stream::RefinedTcpStream as std::io::Write>::write (self=0x7f9f66e120e0, 
    buf=&[u8](len: 154) = {...})
    at /home/steve/.cargo/registry/src/github.com-1ecc6299db9ec823/tiny_http-0.6.0/src/util/refined_tcp_stream.rs:134
#6  0x000055cb827fb9ff in <std::io::buffered::BufWriter<W>>::flush_buf (self=0x7f9f66e120e0)
    at /build/rust/src/rustc-1.25.0-src/src/libstd/io/buffered.rs:459
#7  0x000055cb82802127 in <std::io::buffered::BufWriter<W> as std::io::Write>::flush (self=0x7f9f66e120e0)
    at /build/rust/src/rustc-1.25.0-src/src/libstd/io/buffered.rs:558
#8  0x000055cb828633e2 in <tiny_http::util::sequential::SequentialWriter<W> as std::io::Write>::flush (self=0x7f9f66210030)
    at /home/steve/.cargo/registry/src/github.com-1ecc6299db9ec823/tiny_http-0.6.0/src/util/sequential.rs:139
#9  0x000055cb827b85dc in std::io::impls::<impl std::io::Write for alloc::boxed::Box<W>>::flush (self=0x7fffbadb42a0)
    at /build/rust/src/rustc-1.25.0-src/src/libstd/io/impls.rs:121
#10 0x000055cb827ad2aa in tiny_http::request::Request::respond_impl (self=0x7fffbadb4b38, 
    response=Response<std::io::cursor::Cursor<alloc::vec::Vec<u8>>> = {...})
    at /home/steve/.cargo/registry/src/github.com-1ecc6299db9ec823/tiny_http-0.6.0/src/request.rs:387
#11 0x000055cb827ad3f3 in tiny_http::request::Request::respond (self=Request = {...}, response=...)
    at /home/steve/.cargo/registry/src/github.com-1ecc6299db9ec823/tiny_http-0.6.0/src/request.rs:362
#12 0x000055cb827d3963 in foo::main () at src/main.rs:21

Is there something I'm doing wrong? Thanks for any advice.

@tomaka tomaka added the bug label Apr 22, 2018
@CamJN
Copy link

CamJN commented May 4, 2018

I'm also seeing this, my OS is macOS 10.13.4, rust version is stable 1.25.0.

@gmosx
Copy link

gmosx commented Jan 12, 2020

I think I am seeing the same issue. The ssl.rs example just hangs on me. I am wondering if anyone has any fixes/workarounds for this.

@KyGost
Copy link

KyGost commented May 7, 2021

With #151 released, one would imagine perhaps this is fixed.
Above comment (#144 (comment)) and my experience (nb: my usage involves using tinyhttp via https://github.com/tomaka/rouille) seem to show that perhaps it is not fixed.

Has anyone noticed any success since 0.7.0/#151's merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants