fix: close when throw exception

This commit is contained in:
Weixie Cui 2026-02-19 09:00:54 +08:00
parent dbe45a477b
commit 8f91929a81

View file

@ -1993,11 +1993,16 @@ def getLocalIP():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((conf.hostname, conf.port))
retVal, _ = s.getsockname()
s.close()
except:
debugMsg = "there was an error in opening socket "
debugMsg += "connection toward '%s'" % conf.hostname
logger.debug(debugMsg)
finally:
if s:
try:
s.close()
except:
pass
return retVal