Subject: bug#78920: 30.1; Process sentinel is not called when DNS lookup fails

From: Robert Pluim <[email-masked]>
Date: Mon, 30 Jun 2025 10:01:50 +0200

>>>>> On Sun, 29 Jun 2025 17:22:36 -0400, Shawn Henson <[email-masked]> said:

    Shawn> Robert Pluim <[email-masked]> writes:
    >>>>>>> On Sun, 29 Jun 2025 05:17:18 -0400, Shawn Henson <[email-masked]> said:
    Shawn> I see, though, interestingly if you are to run the `list-processes'
    Shawn> you will see it persist there
    Shawn> indefinitely with a "failed" status.  And if you do kill it, then the
    Shawn> process sentinel will be
    Shawn> called.
    >> 
    >> Hmm, that seems wrong. When using async DNS, which we will only do for
    >> ":nowait t", Emacs will create the process, and then deactivate it
    >> upon DNS failure with a status of "failed". I donʼt think the sentinel
    >> gets called, but I havenʼt tested it.

    Shawn> Sorry, I miswrote, I said "killing", but I meant to say the sentinel only gets
    Shawn> called when *deleting* the process (manually, with `delete-process')
    Shawn> after it has failed. Still, this happens after the process has been
    Shawn> deactivated.

If the view is that we didnʼt call the sentinel because the DNS
failure means we didnʼt create a process, then we shouldnʼt call the
sentinel when we delete the process either.

    >> I wonder what Emacs does for ":nowait t" without async DNS, when the
    >> connect fails. Iʼd expect it to call the sentinel with a "failed"
    >> status.

    Shawn> Is there a trivial way to test this?

Not without recompiling Emacs, but Iʼve just tested it. It results in
an immediate error return from `make-network-process', no process is
created, and the sentinel is not called. Thatʼs all as expected (now
that Iʼve had my coffee 😀).

Eli, what can we do here? Whether or not Emacs is using getaddrinfo_a
should not affect the behaviour here, although having a process be
created is unavoidable, since weʼre deferring the DNS lookup.

The docstring for `make-network-process' says this in the :nowait
section:

    the sentinel function will be called with second arg matching
    "open" (if successful) or "failed" when the connect completes.

Pedantically, the `connect' syscall is not completed, since we never
attempt it because of the DNS failure. But the "attempt to connect to
the remote host" has completed, unsuccessfully, so we should call the
sentinel (and not call it when the process is deleted).

Robert
--