Email or username:

Password:

Forgot your password?
Andrew Tropin

Today I learned: If you don't add (require 'server) before calling (daemonp), your Emacs daemon will silently hang.

The thing I don't actually want to learn at all, ever.

It took 3 hours to debug, I found solution completely accidentially: just forgot to remove it, when was playing with (server-running-p).

#til #emacs #cursedtech

5 comments
zrzz

@abcdw Do you have a minimal test case to reproduce this? I don't see it with my config and emacs -Q --daemon -f daemonp and similar attempts don't hang for me either.

Andrew Tropin

@zrzz

~/tmp/init.el:
(defun test-fn ()
""
(message "fuuuck!")
(when (and (daemonp) (string= server-name "server"))
(message "everything is ok"))
(message "yeah!"))
(add-hook 'after-init-hook 'test-fn)

emacs --fg-daemon=test --no-site-lisp --no-site-file --init-directory=~/tmp

Andrew Tropin

@zrzz Oh, my bad, it's cause of server-name, not daemonp. Today it's me, not a compiler or os. (Still silently hanging).

I thought I tried it in isolation and only later added server-name 🤔

zrzz

@abcdw Looks like the current master correctly prints the error and doesn't hang. So I guess this was fixed sometime after 29.

zrzz

@abcdw Looks like this is actually triggered by the access to the server-name variable which is undefined since it's not autoloaded. Using (defun test-fn () foo) produces the same hang.

Access to the undefined variable throws an error and apparently if you signal an error in after-init-hook while in daemon mode it hangs instead of printing a backtrace. Not sure why that happens.

If I stick a (setq debug-on-error t) at the beginning of the original example then it does produce the expected backtrace:

Debugger entered--Lisp error: (void-variable server-name)
(string= server-name "server")
(and (daemonp) (string= server-name "server"))
(if (and (daemonp) (string= server-name "server")) (progn (message "everything is ok")))
test-fn()
run-hooks(after-init-hook delayed-warnings-hook)
command-line()
normal-top-level()

@abcdw Looks like this is actually triggered by the access to the server-name variable which is undefined since it's not autoloaded. Using (defun test-fn () foo) produces the same hang.

Access to the undefined variable throws an error and apparently if you signal an error in after-init-hook while in daemon mode it hangs instead of printing a backtrace. Not sure why that happens.

Go Up