Subject: bug#50849: 28.0.50; Proposal for Emacs daemon to signal when being busy

From: Eli Zaretskii <[email-masked]>
Date: Tue, 06 Sep 2022 15:22:27 +0300

> From: Visuwesh <[email-masked]>
> Cc: Stefan Kangas <[email-masked]>,  [email-masked],
>   [email-masked],  [email-masked]
> Date: Tue, 06 Sep 2022 09:03:24 +0530
> 
> [செவ்வாய் செப்டம்பர் 06, 2022] Eli Zaretskii wrote:
> 
> >> If someone could check if this works on MS-Windows, that would be
> >> appreciated.
> >
> > How would one test it, please?  Do you have any recipe?
> 
> Here's what I did to test it,
> 
>     % src/emacs -Q --daemon
>     Starting Emacs daemon.
>     % emacsclient --eval '(while t)' &
>     [1] 2700
>     % emacsclient -c --timeout=2
>     Waiting for Emacs...
>     Server not responding; timed out after 2 seconds
>     % emacsclient -c
>     Waiting for Emacs...
>     Server not responding; use Ctrl+C to break  C-c C-c

Thanks.

In fact, one can test this much more easily:

  emacs -Q &
  M-x server-start RET

  emacsclient -w N SOME-FILE
  Waiting for Emacs...

Observe that SOME-FILE is displayed by the server in a client frame.

Now wait for N seconds without doing anything and observe:

  Server not responding; use Ctrl+C to break

IOW, emacsclient _always_ reports a timeout after N seconds, even
though the server did act upon the client request.

Looking at the code, I don't understand how this was supposed to
work.  After sending the request to the server, we call recv in a
loop, waiting for a response.  But in a normal session, the server
will only respond when the user is done with editing the file, which
could be after a very long time.  So this _must_ time out.

I think to make this work, the client-server protocol should be
changed so that the server responds with some kind of positive
response right after it receives the initial request.  And that would
make the protocol backward-incompatible, unfortunately.

Alternatively, perhaps some different change in set_socket and its
subroutines could be used?  Isn't that where we get stuck if the
server is busy?  But I'm really out of my depth here, so would socket
experts please chime in?

And another comment: the documentation says that the default time out
is zero, i.e. no timeout, but that's not true: the default timeout is
actually 30 sec.  So if someone uses the client of the master branch,
it will now always terminate due to timeout after 30 sec...