ninenines / gun

HTTP/1.1, HTTP/2, Websocket client (and more) for Erlang/OTP.
ISC License
898 stars 231 forks source link

Difference between :closed and {:closed, _} #180

Closed 9mm closed 5 years ago

9mm commented 5 years ago

Hey, so far I'm handling all the different errors for fine-grained tuning.

I notice that I have some logs showing up under this (machine_gun proxying errors in Elixir below, not erlang). He told me I should ask here because these failure reasons come from gun

  {:error, %MachineGun.Error{reason: {:closed, _}}} ->

But I have others showing up as this:

  {:error, %MachineGun.Error{reason: :closed}} ->

I'm not quite sure what the difference is?

Thanks!

essen commented 5 years ago

One is from gun_error and the other from gun_down I suppose?

9mm commented 5 years ago

I'm not sure, is there a difference?

essen commented 5 years ago

First one is a request error, second one process is down, recipient of those messages might not be the same process.

9mm commented 5 years ago

Hey, sorry I'm not too familiar with Gun or erlang. What would cause something like that in the case of the 2nd one? How can I fix that?

i'm basically making a huge amount of requests per second, and I'm logging every failure type so I can better tweak/tune each connection (timeouts, pool timeouts, # of connections, etc). I notice I have these two errors and I'm not sure if it's 2 separate problems or the same one (in which case if its just one problem, then a closed connection is just the remote server), but if the 2nd one is a different problem that I can fix than I would like to

essen commented 5 years ago

Same error, different context (request and connection).

petrohi commented 5 years ago

Looking at the code I see that when socket closes there is:

Protocol:close(ProtoState),
Transport:close(Socket),
down(State, closed);

Protocol:close in cases when stream is alive will produce gun_error with {closed, _}. Otherwise down will produce gun_down with closed.

Not sure what alive stream means in the context of HTTP/1. It seem that HTTP/2 does not have this check and always produces gun_error.

Bottom line I think they mean same thing: server closed connection without responding to the request.

9mm commented 5 years ago

Awesome thanks for that translation, I really appreciate it, and thank you essen for your help!

essen commented 5 years ago

Cheers.