Subject: bug#63865: 29.0.90; call-process while owning the X selection hangs other processes

From: Eli Zaretskii <[email-masked]>
Date: Sat, 03 Jun 2023 18:02:31 +0300

> From: Spencer Baugh <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Sat, 03 Jun 2023 10:41:15 -0400
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > Please be specific.  For example, "grep" runs in an async subprocess;
> > we run it with call-process when we probe it for support of some
> > command-line option.  If you can show that these calls take "prolonged
> > period of time", please describe what you do and show the timing.
> 
> No, I mean "grep" called specifically by call-process.  As, for example,
> I see happening in mh-grep-execute-search and nnspool-find-id.  In the
> former case, it's a recursive grep which could take many seconds.
>
> Or as I already mentioned: xref-matches-in-files (used by
> project-find-regexp, C-x p g) uses call-process-region to run recursive
> grep in an arbitrary directory.  Which could easily take minutes.

I hope the respective developers will consider whether it is
reasonably feasible to make those features non-blocking.

> These are understandable designs, and I'm not too bothered by the fact
> that they block Emacs.  But this becomes much worse when they are also
> blocking other applications because of this X selection bug.

Only the buggy ones, let's not forget.  The non-buggy ones could wait
without blocking, just like you expect Emacs to do.

> > AFAIU, the only "everything" that is blocked is an application that
> > happens to request an X selection at that precise time.  That should
> > be rare for short enough call-process runs, since the same user is
> > doing that.
> 
> No, as I mentioned earlier, some (buggy, of course) applications
> frequently request the X selection; such as Slack (and possibly all
> other Electron applications too).  Such applications just immediately
> hang during the entire call-process run without any user interaction.

It is unreasonable to expect Emacs to solve bugs in other
applications.  We are having hard time to solve our own.

> I would be happy with a targeted, specific fix for the bad behavior I
> reported.
> 
> Here's a specific instance that would be good to fix: If I run "M-!
> sleep 30 RET", that will cause some applications to hang while Emacs is
> waiting on the sleep; sometimes (as with Slack) without user
> interaction, or sometimes only if the user tries to paste in them.  Do
> you have a suggestion on how to fix that?

No, I don't.  And I explained why at the very beginning.  I invite you
to read xselect.c and see what kind of processing we do there to
handle selection requests.