{"action":"created","issue":{"url":"https://api.github.com/repos/nahi/httpclient/issues/341","repository_url":"https://api.github.com/repos/nahi/httpclient","labels_url":"https://api.github.com/repos/nahi/httpclient/issues/341/labels{/name}","comments_url":"https://api.github.com/repos/nahi/httpclient/issues/341/comments","events_url":"https://api.github.com/repos/nahi/httpclient/issues/341/events","html_url":"https://github.com/nahi/httpclient/issues/341","id":187164260,"number":341,"title":"timeout does not work with https connections and JRuby","user":{"login":"dgolombek","id":345001,"avatar_url":"https://avatars.githubusercontent.com/u/345001?v=3","gravatar_id":"","url":"https://api.github.com/users/dgolombek","html_url":"https://github.com/dgolombek","followers_url":"https://api.github.com/users/dgolombek/followers","following_url":"https://api.github.com/users/dgolombek/following{/other_user}","gists_url":"https://api.github.com/users/dgolombek/gists{/gist_id}","starred_url":"https://api.github.com/users/dgolombek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgolombek/subscriptions","organizations_url":"https://api.github.com/users/dgolombek/orgs","repos_url":"https://api.github.com/users/dgolombek/repos","events_url":"https://api.github.com/users/dgolombek/events{/privacy}","received_events_url":"https://api.github.com/users/dgolombek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-03T19:16:26Z","updated_at":"2016-11-03T19:25:52Z","closed_at":null,"body":"This is very similar to #206, but for https connections. Taking a page from @ocher's book, sample code:\r\n\r\n```\r\nrequire 'rubygems'\r\nrequire 'socket'\r\nrequire 'thread'\r\nrequire 'httpclient'\r\nrequire 'test/unit'\r\n\r\nclass JRubyHTTPClientReceiveTimeoutBugTest < Test::Unit::TestCase\r\n  TIMEOUT = 1 # seconds\r\n\r\n  def test_should_raise_exception_when_receiving_data_takes_too_long\r\n    httpclient = HTTPClient.new\r\n    httpclient.connect_timeout = TIMEOUT\r\n    httpclient.receive_timeout = TIMEOUT\r\n    httpclient.send_timeout = TIMEOUT\r\n    httpclient.ssl_config.timeout = TIMEOUT\r\n\r\n    begin\r\n      puts \"Connecting\"\r\n      start_time = Time.now\r\n      url = \"https://www.google.com:81\"\r\n      httpclient.get(url)\r\n    rescue HTTPClient::ReceiveTimeoutError, HTTPClient::ConnectTimeoutError => e\r\n      end_time = Time.now\r\n      total_time = end_time - start_time\r\n      assert total_time < TIMEOUT + 1, \"Receiving data took too much time: #{total_time}\"\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nRunning with MRI 2.3.0, that works just fine. With JRuby 9.1.5.0, it takes ~30 seconds to timeout. This may well be a JRuby bug, like #206, but I think that it's a HTTPClient issue. If I understand correctly, I think that at https://github.com/nahi/httpclient/blob/master/lib/httpclient/jruby_ssl_socket.rb#L444 we should only create the Socket if a proxy is specified. If no proxy is present, at https://github.com/nahi/httpclient/blob/master/lib/httpclient/jruby_ssl_socket.rb#L500 we should be doing\r\n\r\n```\r\nsocket = factory.createSocket(); \r\nsocket_addr = InetSocketAddress.new(dest.site.host, dest.site.port)\r\nif session.ssl_config.timeout\r\n    socket.connect(socket_addr, session.ssl_config.timeout / 1000); \r\nelse\r\n    socket.connect(socket_addr); \r\nend\r\nsocket.setSoTimeout(session.ssl_config.timeout / 1000) if session.ssl_config.timeout\r\n```\r\n\r\nThat's pretty rough, but I think it's why no timeout is happening. It does point out that ssl_config only has a single timeout instead of both a connect_timeout and send/receive timeouts. It also makes me wonder why there is a separate SSL timeout at all, instead of automatically sharing the default timeouts.\r\n\r\nNote: In my test, I'm using a known host with firewall that's dropping SYN  packets here to simulate a really bad case. If I change the test from #206 to use https, it times out after 3 seconds -- better, although still not perfect. But I did run into this bug in the real world, with a host that was failing in a really bad way."},"comment":{"url":"https://api.github.com/repos/nahi/httpclient/issues/comments/258248378","html_url":"https://github.com/nahi/httpclient/issues/341#issuecomment-258248378","issue_url":"https://api.github.com/repos/nahi/httpclient/issues/341","id":258248378,"user":{"login":"dgolombek","id":345001,"avatar_url":"https://avatars.githubusercontent.com/u/345001?v=3","gravatar_id":"","url":"https://api.github.com/users/dgolombek","html_url":"https://github.com/dgolombek","followers_url":"https://api.github.com/users/dgolombek/followers","following_url":"https://api.github.com/users/dgolombek/following{/other_user}","gists_url":"https://api.github.com/users/dgolombek/gists{/gist_id}","starred_url":"https://api.github.com/users/dgolombek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgolombek/subscriptions","organizations_url":"https://api.github.com/users/dgolombek/orgs","repos_url":"https://api.github.com/users/dgolombek/repos","events_url":"https://api.github.com/users/dgolombek/events{/privacy}","received_events_url":"https://api.github.com/users/dgolombek/received_events","type":"User","site_admin":false},"created_at":"2016-11-03T19:25:52Z","updated_at":"2016-11-03T19:25:52Z","body":"In all the timeout logic above, it should clearly be * 1000, not / 1000. "}}
{"actor":{"display_login":"dgolombek"}}