fix: prevent UnboundLocalError in sd_notify when socket creation fails

This commit is contained in:
Kadir Can Ozden 2026-02-20 06:16:54 +03:00
parent 2d4310116d
commit 41c6bf8e3e

View File

@ -61,6 +61,7 @@ def sd_notify(state, logger, unset_environment=False):
if addr is None:
# not run in a service, just a noop
return
sock = None
try:
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM | socket.SOCK_CLOEXEC)
if addr[0] == '@':
@ -72,4 +73,5 @@ def sd_notify(state, logger, unset_environment=False):
finally:
if unset_environment:
os.environ.pop('NOTIFY_SOCKET')
sock.close()
if sock is not None:
sock.close()