fix: close when throw exception (#6019)

This commit is contained in:
cui 2026-02-21 21:35:26 +08:00 committed by GitHub
parent dbe45a477b
commit d2106f278e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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