{"action":"created","issue":{"url":"https://api.github.com/repos/tokio-rs/tokio-minihttp/issues/6","repository_url":"https://api.github.com/repos/tokio-rs/tokio-minihttp","labels_url":"https://api.github.com/repos/tokio-rs/tokio-minihttp/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/tokio-rs/tokio-minihttp/issues/6/comments","events_url":"https://api.github.com/repos/tokio-rs/tokio-minihttp/issues/6/events","html_url":"https://github.com/tokio-rs/tokio-minihttp/issues/6","id":179384860,"number":6,"title":"hanging connection - tests with ab","user":{"login":"szagi3891","id":859451,"avatar_url":"https://avatars.githubusercontent.com/u/859451?v=3","gravatar_id":"","url":"https://api.github.com/users/szagi3891","html_url":"https://github.com/szagi3891","followers_url":"https://api.github.com/users/szagi3891/followers","following_url":"https://api.github.com/users/szagi3891/following{/other_user}","gists_url":"https://api.github.com/users/szagi3891/gists{/gist_id}","starred_url":"https://api.github.com/users/szagi3891/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szagi3891/subscriptions","organizations_url":"https://api.github.com/users/szagi3891/orgs","repos_url":"https://api.github.com/users/szagi3891/repos","events_url":"https://api.github.com/users/szagi3891/events{/privacy}","received_events_url":"https://api.github.com/users/szagi3891/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-09-27T02:45:40Z","updated_at":"2016-10-23T05:39:27Z","closed_at":"2016-10-22T00:15:25Z","body":"I have this code :\r\n\r\n```\r\nextern crate tokio_proto;\r\nextern crate tokio_service;\r\nextern crate tokio_minihttp as http;\r\nextern crate futures;\r\nextern crate futures_cpupool;\r\nextern crate env_logger;\r\n\r\nuse tokio_service::Service;\r\nuse futures::{Async, Future};\r\nuse std::io;\r\nuse futures_cpupool::CpuPool;\r\nuse std::time;\r\nuse std::io::Read;\r\nuse std::fs::File;\r\nuse std::sync::{Arc, Mutex};\r\n\r\n#[derive(Clone)]\r\nstruct HelloWorld {\r\n    pool: CpuPool,\r\n    counter: Arc<Mutex<u32>>,\r\n}\r\n\r\nimpl HelloWorld {\r\n    fn new() -> HelloWorld {\r\n        HelloWorld {\r\n            pool: CpuPool::new(4),\r\n            counter: Arc::new(Mutex::new(0)),\r\n        }\r\n    }\r\n\r\n    fn get_counter(&self) -> u32 {\r\n        let mut guard = self.counter.lock().unwrap();\r\n\r\n        let counter = *guard;\r\n        *guard += 1;\r\n        counter\r\n    }\r\n}\r\n\r\nimpl Service for HelloWorld {\r\n    type Request = http::Request;\r\n    type Response = http::Response;\r\n    type Error = io::Error;\r\n    type Future = Box<Future<Item=http::Response, Error=io::Error>>;\r\n    \r\n    fn call(&self, _request: http::Request) -> Self::Future {\r\n\r\n        //let (sender, receiver) = futures::oneshot();\r\n        let mut resp = http::Response::new();\r\n        let request_number = self.get_counter();\r\n\r\n        println!(\"spanw run: {:?}\", request_number);\r\n\r\n        self.pool.spawn_fn(move || -> Result<String, io::Error> {\r\n            let s = get_file(\"./test.txt\".to_owned());\r\n            println!(\"open file {:?}\", request_number);\r\n            Ok(s)\r\n        }).and_then(move |str| {\r\n            resp.body(str.as_str());\r\n            Ok(resp)\r\n        }).boxed()\r\n    }\r\n\r\n    fn poll_ready(&self) -> Async<()> {\r\n        Async::Ready(())\r\n    }\r\n}\r\n\r\nfn get_file(path: String) -> String {\r\n    let mut f = File::open(path.as_str()).unwrap();\r\n    let mut s = String::new();\r\n    f.read_to_string(&mut s).unwrap();\r\n\r\n    s\r\n}\r\n\r\npub fn main() {\r\n    let _ = ::env_logger::init();\r\n\r\n    let addr = \"0.0.0.0:8080\".parse().unwrap();\r\n\r\n    println!(\"start server at: 0.0.0.0:8080\");\r\n\r\n    http::serve(addr, HelloWorld::new());\r\n}\r\n```\r\n\r\nWhen I run ab :\r\n```\r\ngrzegorz@grzegorz:~/Pulpit/rust/test_http_futures$ ab -n 100 -c 10 http://127.0.0.1:8080/\r\nThis is ApacheBench, Version 2.3 <$Revision: 1604373 $>\r\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\r\nLicensed to The Apache Software Foundation, http://www.apache.org/\r\n\r\nBenchmarking 127.0.0.1 (be patient)...apr_pollset_poll: The timeout specified has expired (70007)\r\n```\r\n\r\nOut from server :\r\n```\r\ngrzegorz@grzegorz:~/Pulpit/rust/test_http_futures$ cargo run --example static\r\n    Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs\r\n     Running `target/debug/examples/static`\r\nstart server at: 0.0.0.0:8080\r\nspanw run: 0\r\nopen file 0\r\nspanw run: 1\r\nopen file 1\r\nspanw run: 2\r\nopen file 2\r\nspanw run: 3\r\nopen file 3\r\nspanw run: 4\r\nopen file 4\r\nspanw run: 5\r\nopen file 5\r\nspanw run: 6\r\nopen file 6\r\nspanw run: 7\r\nopen file 7\r\nspanw run: 8\r\nopen file 8\r\nspanw run: 9\r\nopen file 9\r\n```\r\n\r\nIt seems that the server can not handle another request in the same connection.\r\n\r\nhelp please :)"},"comment":{"url":"https://api.github.com/repos/tokio-rs/tokio-minihttp/issues/comments/255570898","html_url":"https://github.com/tokio-rs/tokio-minihttp/issues/6#issuecomment-255570898","issue_url":"https://api.github.com/repos/tokio-rs/tokio-minihttp/issues/6","id":255570898,"user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"created_at":"2016-10-23T05:39:27Z","updated_at":"2016-10-23T05:39:27Z","body":"Ah yeah right now this relies on an unpublished version of tokio-core, but you can use that with a `[replace]` section like this -- https://github.com/tokio-rs/tokio-minihttp/blob/master/Cargo.toml#L21-L22"}}
{"actor":{"display_login":"alexcrichton"}}