close socket in getPrimaryIPAddr even if exception occurs (#15558)
This commit is contained in:
parent
30b966bdf7
commit
1f51a33998
1 changed files with 5 additions and 3 deletions
|
|
@ -2005,6 +2005,8 @@ proc getPrimaryIPAddr*(dest = parseIpAddress("8.8.8.8")): IpAddress =
|
||||||
newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
|
newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
|
||||||
else:
|
else:
|
||||||
newSocket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)
|
newSocket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)
|
||||||
socket.connect($dest, 80.Port)
|
try:
|
||||||
result = socket.getLocalAddr()[0].parseIpAddress()
|
socket.connect($dest, 80.Port)
|
||||||
socket.close()
|
result = socket.getLocalAddr()[0].parseIpAddress()
|
||||||
|
finally:
|
||||||
|
socket.close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue