Skip to content

Commit d2106f2

Browse files
authored
fix: close when throw exception (#6019)
1 parent dbe45a4 commit d2106f2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/core/common.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,11 +1993,16 @@ def getLocalIP():
19931993
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
19941994
s.connect((conf.hostname, conf.port))
19951995
retVal, _ = s.getsockname()
1996-
s.close()
19971996
except:
19981997
debugMsg = "there was an error in opening socket "
19991998
debugMsg += "connection toward '%s'" % conf.hostname
20001999
logger.debug(debugMsg)
2000+
finally:
2001+
if s:
2002+
try:
2003+
s.close()
2004+
except:
2005+
pass
20012006

20022007
return retVal
20032008

0 commit comments

Comments
 (0)