When running xlb function the code gets stuck in a native endless loop. The patch I have added closes the fd of the xserver, which as a side effect ends the endless loop. Some would say this patch is fixing a bug of a dependency of emacs and not emacs itself (it is just that emacs uses it in a certain way...).
This solution uses native timer (using signals) to detect the timeout. Upon reaching a timeout it closes an the fd on the same thread as the xlb code (this is because of how signals works).
To do this is lisp we need to answer the following:
1. How to find the fd of the current xserver using lisp?
2. How to call syscall close using lisp?
3. How to create native timers using lisp?
4. Is it even allowed to run lisp code while the main thread is in xlb native code (stack frame is deep inside other library and this other library was called from lisp).

On Sat, Feb 12, 2022, 09:18 Lars Ingebrigtsen <larsi@gnus.org> wrote:
> This native function closes the fd of the xcb and causes the select to
> return EINTR. xcb have internal infinate loop Incase of EINTR, so closing
> the fd is necessary to get out of this infinite loop. Closing the fd also
> causes libx11 to realize the connection was closed and call the error
> handler of emacs for x11 failures for a clean termination of the resources
> in emacs.

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

I don't think it would be appropriate to add a function like this to the
C level of Emacs, because the use case is very limited.  And I think you
can basically get the same functionality by using the xelb package
(which talks to the X servers from Lisp).

So I'm closing this bug report as a "wontfix".

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no