restart-emacs icon indicating copy to clipboard operation
restart-emacs copied to clipboard

Can't reconnect to the daemon

Open danielkrizian opened this issue 5 years ago • 4 comments

I have started emacs (v26.1) server:

$ emacs --daemon

I connected using

$ emacsclient -t

From within emacs, well spacemacs, I restarted the daemon SPC q r, which executed dotspacemacs/resume-emacs-resume-layouts tied to restart-emacs.el.

After daemon restarted, I see the process in htop running but can't reconnect to it.

$ htop

  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command                                                                                                                                    
 6579 dk         20   0  232M  164M  9664 S  0.0  0.3  0:05.46 /opt/conda/bin/emacs --daemon=server --resume-layouts --restart-emacs-desktop /tmp/restart-emacs-desktopOpor7P
 6578 dk         20   0 77948 11348 10024 S  0.0  0.0  0:00.00 /opt/conda/bin/emacs --daemon=server --resume-layouts --restart-emacs-desktop /tmp/restart-emacs-desktopOpor7P  

I was expecting to see the message Emacs daemon restarted! Use '%s -nw -s %s %s' to reconnect to it pop up in my bash terminal, but it does not appear.

How can I reconnect to the server? I tried this:

$ emacsclient --s server -t
emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".
emacsclient: error accessing socket "server"
$ 

Can I use the /tmp/restart-emacs-desktopOpor7P information somehow?

danielkrizian avatar Feb 20 '19 23:02 danielkrizian

Hi @danielkrizian, this might happen if Emacs is not able to start successfully in the daemon mode, possibly due to some bug in init file, could try running /opt/conda/bin/emacs --daemon=server --resume-layouts --restart-emacs-desktop <desktop file> yourself, this might given some hint as to what went wrong. As to using the information in desktop file, you use the function restart-emacs--restore-frames-using-desktop to load frames from the desktop file, do something like (restart-emacs--restore-frames-using-desktop "<desktop file>")

iqbalansari avatar Mar 07 '19 07:03 iqbalansari

Hi @iqbalansari, thanks, I tried running as you suggested, still don't get the expected behavior, i.e. don't get the expected message Emacs daemon restarted! Use '%s -nw -s %s %s' to reconnect to it and the terminal does not show the restored emacs buffers from previous session.

Step by step what I did:

$ emacs --daemon
$ emacsclient -t

In the open Spacemacs terminal session that pops up, SPC q r tied to dotspacemacs/resume-emacs-resume-layouts. I am now back in the terminal.

$ htop
  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command                                                                                                                                                                                
23102 dk         20   0  189M  124M  8776 S  0.0  0.2  0:03.47 /opt/conda/bin/emacs --daemon=server --resume-layouts --restart-emacs-desktop /tmp/restart-emacs-desktopdBkj0J                                                                  
22953 dk         20   0  231M  166M  8768 S  0.0  0.3  0:04.78 /opt/conda/bin/emacs --daemon=server --resume-layouts --restart-emacs-desktop /tmp/restart-emacs-desktopdBkj0J

$ /opt/conda/bin/emacs --daemon=server --resume-layouts --restart-emacs-desktop /tmp/restart-emacs-desktopdBkj0J
Loading /home/dk/dotfiles/.spacemacs.d/init.el (source)...
Loading /home/dk/dotfiles/.spacemacs.d/init.el (source)...done
Loading /home/dk/dotfiles/.emacs.d/custom.el (source)...
Loading t-mouse...
Loading t-mouse...done
Loading xt-mouse...
Loading xt-mouse...done
Loading /home/dk/dotfiles/.emacs.d/custom.el (source)...done
spacemacs buffer error: (beginning-of-buffer)
Eshell virtualenv support initialized.
Spacemacs is ready.
No desktop file.

$

Note the last command prompt ($). At this point I would have expected message in the terminal saying Emacs daemon restarted! Use '%s -nw -s %s %s' to reconnect to it. Instead I am back in the terminal and see the third emacs process running in htop, without being able to attach to it and see the usual emacs terminal environment buffers.

$ htop
  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command                                                                                                                                                                                
23102 dk         20   0  189M  124M  8776 S  0.0  0.2  0:03.47 /opt/conda/bin/emacs --daemon=server --resume-layouts --restart-emacs-desktop /tmp/restart-emacs-desktopdBkj0J                                                                  
22953 dk         20   0  231M  166M  8768 S  0.0  0.3  0:04.78 /opt/conda/bin/emacs --daemon=server --resume-layouts --restart-emacs-desktop /tmp/restart-emacs-desktopdBkj0J
22952 dk         20   0 74812 11620 10276 S  0.0  0.0  0:00.01 /opt/conda/bin/emacs --daemon=server --resume-layouts --restart-emacs-desktop /tmp/restart-emacs-desktopdBkj0J

danielkrizian avatar Mar 07 '19 07:03 danielkrizian

This seems like the problematic error

spacemacs buffer error: (beginning-of-buffer)

It seems this error is preventing Emacs init from completely running and thus restart-emacs's startup hook which prints this message is never getting a chance

iqbalansari avatar Mar 09 '19 13:03 iqbalansari

Hello @danielkrizian, any update on this? Is this still happening?

iqbalansari avatar Apr 28 '20 06:04 iqbalansari