Skip to content

race condition with systemd notification protocol #505

Open

Description

@aanderse

when setting notify to systemd there can be a problem if a daemon starts too early - the sd_notify socket isn't bound until after the fork

Activity

  1. troglobit commented on Sep 14, 2026

    @troglobit
    Collaborator

    Could you give an example to help me understand? Because often the call to sd_notify(), or pidfile creation, is actually malplaced in the daemon itself.

  2. aanderse commented on Sep 15, 2026

    @aanderse
    ContributorAuthor

    imagine a daemon tries to access NOTIFY_SOCKET before it does anything else... since finit forks the process first it would be possible that the socket isn't bound yet...

    i have a user running systemd-udev in their initramfs and they weren't getting a ready condition for the daemon... we ended up creating a script to test this out...

        #!/bin/sh
        if [ -n "''${NOTIFY_SOCKET:-}" ]; then
          found=
          tries=0
          while [ -z "$found" ] && [ "$tries" -lt 100000 ]; do
            while read -r _ _ _ _ _ _ _ name; do
              if [ "$name" = "$NOTIFY_SOCKET" ]; then
                found=1
                break
              fi
            done < /proc/net/unix
            tries=$((tries + 1))
          done
        fi
        exec "$@"
    

    the command was that script followed by calling udev and this fixed the issue for them

    i ended up creating a vm test to reproduce and was able to... in some cases i got up to 1158 tries before the name appeared

    note that we have only been able to reproduce this in an initramfs so far

  3. troglobit commented on Sep 16, 2026

    @troglobit
    Collaborator

    Aha, got it! I'll see what my friend can make of it while we await review on #500 (stalling my pipeline atm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions