benoitc / hackney

simple HTTP client in Erlang
Other
1.34k stars 427 forks source link

time to create a new connection #684

Closed davemenninger closed 3 years ago

davemenninger commented 3 years ago

I'm having trouble figuring out what might be the cause of this latency ( minutes to create a connection ). The strange thing is that it does eventually succeed:

https://github.com/benoitc/hackney/blob/v1.17.0/src/hackney_pool.erl#L101-L107

[hackney trace 60 <0.4357.0> 2021:04:07 18:38:39 4336] HTTP proxy request 
   Content: [{module,hackney},
             {line,622},
             {url,<<"http://redacted.company.internal:8192/">>}]
[hackney trace 60 <0.4357.0> 2021:04:07 18:38:39 4337] connect 
   Content: [{module,hackney_connect},
             {line,32},
             {transport,hackney_http_connect},
             {host,"redacted.company.internal"},
             {port,8192},
             {dynamic,true}]
[hackney trace 80 <0.4392.0> 2021:04:07 18:38:39 4339] no socket in the pool 
   Content: [{module,hackney_pool},{line,101},{pool,default}]

...

[hackney trace 80 <0.4392.0> 2021:04:07 18:43:01 4487] new connection 
   Content: [{module,hackney_pool},{line,107}]
[hackney trace 60 <0.4357.0> 2021:04:07 18:43:01 4487] reuse a connection 
   Content: [{module,hackney_connect},{line,216},{pool,default}]
[hackney trace 40 <0.4357.0> 2021:04:07 18:43:01 4487] perform request 
   Content: [{module,hackney_request},
             {line,106},
             {header_data,[  redacted ]]},
             {perform_all,true},
             {expect,false}]
[hackney trace 80 <0.4357.0> 2021:04:07 18:43:01 4642] got response 

This is an HTTPS connection with a client certificate. I think I can see hackney making calls to ssl and public_key but I can't tell for sure beyond that.

Is it possible something in the SSL handshake takes so long? Or something with the OS sockets?

Once the pool has a connection, it is reused subsequently and is very fast.

davemenninger commented 3 years ago

In my case it turned out to be a misconfigured load balancer in the stack. Sorry to bother!