Merge pull request #3522 from bysiber/fix-sd-notify-unbound-error

fix: prevent UnboundLocalError in sd_notify when socket creation fails
This commit is contained in:
Benoit Chesneau 2026-02-20 13:42:51 +01:00 committed by GitHub
commit 32e46a58ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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()