ostinelli / net-http2

NetHttp2 is an HTTP/2 client for Ruby.
MIT License
141 stars 31 forks source link

timeout for client.call #13

Closed mvalitov closed 7 years ago

mvalitov commented 7 years ago

Hello, I know that I can specify a timeout for connections:

client = NetHttp2::Client.new(
  "#{uri.scheme}://#{uri.host}", 
  {proxy_addr: "#{proxy.scheme}://#{proxy.host}", proxy_port: "#{proxy.port}", 
  proxy_user: nil, 
  proxy_pass: nil, 
  connect_timeout: 10} )

but has not found it possible to specify for the timeout for a call? in some cases, my program freezes on call

      response = client.call(options[:method], uri.path,
        headers: options[:headers],
        body: compressed_data)
ostinelli commented 7 years ago

From the README:

Blocking calls

These behave similarly to HTTP/1 calls.

  • call(method, path, options={})NetHttp2::Response or nil

    Sends a request. Returns nil in case a timeout occurs.

    method is a symbol that specifies the :method header (:get, :post, :put, :patch, :delete, :options). The body, headers and query-string params of the request can be specified in the options, together with the timeout.

mvalitov commented 7 years ago

Thanks!

mvalitov commented 7 years ago

Is this code correct?

response = client.call(options[:method], uri.path,
  headers: options[:headers],
  body: compressed_data,
  timeout: 60)
mvalitov commented 7 years ago

I did so:

logger.info "initialize NetHttp2 client"
client = NetHttp2::Client.new("#{uri.scheme}://#{uri.host}", {proxy_addr: "#{proxy.scheme}://#{proxy.host}", proxy_port: "#{proxy.port}", proxy_user: nil, proxy_pass: nil, connect_timeout: 10} )
logger.info "start client.call"
response = client.call(options[:method], uri.path,
  headers: options[:headers],
  body: compressed_data,
  timeout: 60)
logger.info "client close"
client.close

and I periodically freezes after "start client.call"

ilyaerin commented 7 years ago

I have the same problem after the last gem update.

With version 0.14.0 I use this code, and it works fine!

domain = 'https://....'
path = '/...'
ip = 'xx.xx.xx.xx'
port = 80
client = NetHttp2::Client.new(domain, {proxy_addr: ip, proxy_port: port})
client.call(:get, path)

I've tried to use any format of proxy addresses with the last version 0.14.1, but in all cases I've got a timeout error. I don't have a problem with proxy, it's my private proxy server and it works.

As example, this code doesn't work:

domain = 'https://....'
path = '/...'
ip = 'http://xx.xx.xx.xx'
port = 80
client = NetHttp2::Client.new(domain, {proxy_addr: ip, proxy_port: port})
client.call(:get, path)

Can you check this, please? Probably the problem with http/1.1, that is used for proxies connections or with address of proxy server in IP format xx.xx.xx.xx.

mvalitov commented 7 years ago

@ilyaerin , I checked with the version 1.14.1, and it works. freezing problem fixed so:

response = Timeout::timeout(timeout) { client.call(options[:method], uri.path,
  headers: options[:headers],
  body: compressed_data)
}
ostinelli commented 7 years ago

With version 0.14.0 I use this code, and it works fine!

@ilyaerin 0.14.0 didn't have proxy support so the call cannot have worked with a proxy. It would have just ignored the proxy params.

Can you check this, please? Probably the problem with http/1.1, that is used for proxies connections or with address of proxy server in IP format xx.xx.xx.xx.

Maybe @Nattfodd can help since he added the proxy support in.

nattfodd commented 7 years ago

Sadly, I can't say what goes wrong on your side. I can say for sure, that "http://xx.xx.xx.xx" format is okay, I've tested it. I may suggest you to check this out with an external http proxy server, in which you're 100% sure.

As example, this code doesn't work:

domain = 'https://....'
path = '/...'
ip = 'http://xx.xx.xx.xx'
port = 80
client = NetHttp2::Client.new(domain, {proxy_addr: ip, proxy_port: port})
client.call(:get, path)

Can you check this, please? Probably the problem with http/1.1, that is used for proxies connections or with address of proxy server in IP format xx.xx.xx.xx.

ostinelli commented 7 years ago

Closed due to no additional activity.