@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()