emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

DOS bug with sshx, xserver, emacsclient, reconnection.


From: otadmor .
Subject: DOS bug with sshx, xserver, emacsclient, reconnection.
Date: Fri, 2 Aug 2019 17:37:14 +0300

(the patch for fixing this bug is attached, the original thread in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=36362)

Hi,
I have this scenerio:
1. Laptop with Windows 10 host and Ubuntu 1804 vm.putty and xming
(latest versions) are installed on host and emacs 26.2 on the vm.
2. Connect with putty via sshx to the vm and run emacsclient -c.
Doesn't really matter how emacs deamon is started (from emacs
"server-start" function, via the ssh using "emacs --daemon", or as a
service "sysctl -user start emacs").
3. Close the laptop lid so it goes to sleep.
4. Open the lid and reconnect with sshx and emacsclient -c.
5. The second emacsclient causes emacs daemon to stuck on xcb select
(they have no timeout). Note the emacs daemon (x client) is still
running correctly before the second emacsclient tries to connect.

The propose is to have this connectivity check native function + elisp timer
which executes it on all existing frames every few seconds. The
server-sentinel will also call the native function just in case the
elisp timer was not executed before any new client connection. I use
this on my own configuration and emacs compilation because its
impossible for me otherwise.

The patch has native function which 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.

This native function is consist of a a native timer with a signal
handler to handle when this timer expires. I have set the native timer
for 0.5 seconds and it is configurable using an elisp variable. When
the server was not disconnected this timer don't expires, don't close
the fd and return immediately without waiting 0.5 seconds. When the
client crashed because of sleep, the native code will have to wait
before realizing it.

I have selected GetGeomerty arbitrarly as a command sent to the
xserver and wait for its reply. This command usually used by emacs and
I don't believe it has an extra side effect. The xcb knows the
sequence numbers of the requests and should not be confused with other
GetGeomerty/other non-GetGeomerty requests.

The elisp timer function and server-sentinel hook:

(defun check-frames-connection-timer ()
  (safe-check-frames-connection)
  (run-at-time 2 nil 'check-frames-connection-timer))

(defun safe-x-check-frame (frame)
  (condition-case nil
      (x-check-frame frame)
    (error nil)))

(defun safe-check-frames-connection ()
  (when (functionp 'x-check-frame)
    (dolist (frame (frame-list))
      (when (eq (framep frame) 'x)
        (safe-x-check-frame frame)))))

(defun server-sentinel-hook (&rest _)
  (safe-check-frames-connection))

(run-at-time 2 nil 'check-frames-connection-timer)
(advice-add 'server-sentinel :before #'server-sentinel-hook)

-- 
Gretz,
Ofir Tadmor

ICQ: 77685691
Mail: address@hidden

Attachment: 0001-Add-x-check-frame-lisp-method-to-check-frame-x-serve.patch
Description: Binary data

Attachment: xterm.c.26.2.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]