aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-03-25 10:30:10 +0100
committerLoïc Hoguin <[email protected]>2020-03-25 10:30:10 +0100
commit3deadc01ee34e27cfba49b78debcf8006d7d7e1c (patch)
tree12acd159d281fc8ced721f01a2465b184c9b39ad /src
parentc1c9341255bdd6664e4c69093cc2e84d7dc43bb9 (diff)
downloadgun-3deadc01ee34e27cfba49b78debcf8006d7d7e1c.tar.gz
gun-3deadc01ee34e27cfba49b78debcf8006d7d7e1c.tar.bz2
gun-3deadc01ee34e27cfba49b78debcf8006d7d7e1c.zip
Fix crash in gun:info/1 when socket is closed
The call to Transport:sockname/1 can return an error if the socket was closed as we were gathering info. In that case we simply do not fill in the address and port information.
Diffstat (limited to 'src')
-rw-r--r--src/gun.erl14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/gun.erl b/src/gun.erl
index b8030cf..3255c67 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -442,11 +442,15 @@ info(ServerPid) ->
undefined ->
Info0;
_ ->
- {ok, {SockIP, SockPort}} = Transport:sockname(Socket),
- Info0#{
- sock_ip => SockIP,
- sock_port => SockPort
- }
+ case Transport:sockname(Socket) of
+ {ok, {SockIP, SockPort}} ->
+ Info0#{
+ sock_ip => SockIP,
+ sock_port => SockPort
+ };
+ {error, _} ->
+ Info0
+ end
end,
case Protocol of
undefined -> Info;