From 3deadc01ee34e27cfba49b78debcf8006d7d7e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 25 Mar 2020 10:30:10 +0100 Subject: 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. --- src/gun.erl | 14 +++++++++----- 1 file 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; -- cgit v1.2.3