radian-software / straight.el

πŸ€ Next-generation, purely functional package manager for the Emacs hacker.
MIT License
2.72k stars 150 forks source link

Emacs freeze when using `watchexec` to improve startup #599

Closed bangedorrunt closed 4 years ago

bangedorrunt commented 4 years ago

What's wrong

emacs freeze when scrolling down after use this snippet

Directions to reproduce

Add the following snippet in init.el before straight.el bootstrap

 (if (and (executable-find "watchexec")
          (executable-find "python3"))
     (setq straight-check-for-modifications '(watch-files find-when-checking))
   (setq straight-check-for-modifications
         '(find-at-startup find-when-checking)))

Open Emacs, scrolling down until screen refresh, Emacs will freeze and have to kill it.

Version information

progfolio commented 4 years ago

Which case is the freeze occurring for? It would be helpful to know what the value of straight-check-for-modifications is when you experience the freeze.

bangedorrunt commented 4 years ago

@progfolio It's my bad. I couldn't reproduce the problem with new updated gccemacs. So I think that I used a "bad-git-commit" compiled gccemacs at the time.

bangedorrunt commented 4 years ago

@progfolio, now it happened again. Same snippet:

 (if (and (executable-find "watchexec")
          (executable-find "python3"))
     (setq straight-check-for-modifications '(watch-files find-when-checking))
   (setq straight-check-for-modifications
         '(find-at-startup find-when-checking)))

FYI, I'm using evil-mode, so moving around, make some random edit then Emacs freeze. I opened new terminal, accessed freezing emacs with kill -USR2 pid, and it showed this bug

Screen Shot 2020-10-05 at 3 48 40 pm

If I comment out the above snippet, the issue's gone.

Please let me know if you need any further information

progfolio commented 4 years ago

Could you try evaluating this in your *scratch* buffer?:

(straight-bug-report
  :pre-bootstrap
  (if (and (executable-find "watchexec")
           (executable-find "python3"))
      (setq straight-check-for-modifications '(watch-files find-when-checking))
    (setq straight-check-for-modifications
          '(find-at-startup find-when-checking)))
  :post-bootstrap
  (message "straight-check-for-modifications: %S" straight-check-for-modifications))

It will bootstrap straight in a clean environment and give us some more information. After the test is run, a window should open with the output. You can paste that entire window's content here.

bangedorrunt commented 4 years ago

@progfolio Pls have a look

Screen Shot 2020-10-05 at 4 03 12 pm
bangedorrunt commented 4 years ago

In shell, I link the compiled gccemacs with


# Need this if I use `gccemacs`
if [[ "$OSTYPE" == "darwin"* ]]; then
  if [ -f "/Applications/Emacs.app/Contents/MacOS/Emacs" ]; then
    alias edaemon="/Applications/Emacs.app/Contents/MacOS/Emacs --daemon"
    alias emacs="/Applications/Emacs.app/Contents/MacOS/Emacs -nw"
  fi

  if [ -f "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" ]; then
    alias ekill="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -nw -e '(kill-emacs)'"
    alias e="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -nw -a=''"
  fi
fi
progfolio commented 4 years ago

I see. You can add a key val pair to that bug-report to specify the executable path:

(straight-bug-report
  :executable "/Applications/Emacs.app/Contents/MacOS/Emacs"
  :pre-bootstrap
  (if (and (executable-find "watchexec")
           (executable-find "python3"))
      (setq straight-check-for-modifications '(watch-files find-when-checking))
    (setq straight-check-for-modifications
          '(find-at-startup find-when-checking)))
  :post-bootstrap
  (message "straight-check-for-modifications: %S" straight-check-for-modifications))
bangedorrunt commented 4 years ago

Here you are

Test Case ```emacs-lisp (straight-bug-report :executable "/Applications/Emacs.app/Contents/MacOS/Emacs" :pre-bootstrap (if (and (executable-find "watchexec") (executable-find "python3")) (setq straight-check-for-modifications '(watch-files find-when-checking)) (setq straight-check-for-modifications '(find-at-startup find-when-checking))) :post-bootstrap (message "straight-check-for-modifications: %S" straight-check-for-modifications)) ```
Output ```emacs-lisp Bootstrapping straight.el... Bootstrapping straight.el...done Rebuilding all packages due to build cache schema change Looking for gnu-elpa-mirror recipe β†’ Cloning melpa... Looking for gnu-elpa-mirror recipe β†’ Cloning melpa...done Looking for emacsmirror-mirror recipe β†’ Cloning gnu-elpa-mirror... Looking for emacsmirror-mirror recipe β†’ Cloning gnu-elpa-mirror...done Looking for straight recipe β†’ Cloning emacsmirror-mirror... Looking for straight recipe β†’ Cloning emacsmirror-mirror...done Building straight... Building straight...done Setting up filesystem watcher... Setting up filesystem watcher...done Test run with version: prerelease (HEAD -> develop, origin/develop) 64e5361 2020-10-01 straight-check-for-modifications: (watch-files find-when-checking) ```
progfolio commented 4 years ago

Thank you. Another thing to try:

(straight-bug-report
  :interactive t
  :executable "/Applications/Emacs.app/Contents/MacOS/Emacs"
  :pre-bootstrap 
  (if
      (and
       (executable-find "watchexec")
       (executable-find "python3"))
      (setq straight-check-for-modifications
            '(watch-files find-when-checking))
    (setq straight-check-for-modifications
          '(find-at-startup find-when-checking)))
  :post-bootstrap 
  (message "straight-check-for-modifications: %S" straight-check-for-modifications))

This will start an interactive Emacs session in a clean environment. Your init won't be loaded, (and so no Evil), but can you see if you can reproduce the problem by moving around in that environment?

If you are able to get it to freeze, send the same USR2 signal and copy the entire output of the backtrace buffer here.

bangedorrunt commented 4 years ago

@progfolio I coulnd't reproduce the error. So it's not straight.el bug, right?

progfolio commented 4 years ago

I'm not 100% sure yet. If you go back to your set-up and trigger the freeze, does pressing C-g unfreeze Emacs? (You may have to press it several times)

If it does, you can M-x toggle-debug-on-quit before the freeze and you should get a similar backtrace to what you posted in the image earlier. I'd be interested to see the full output of that backtrace buffer. You can also step through that using the d key to see what's being executed. This may give a clue as to what is causing the freeze. (you can still step through the backtrace with the SIG USR2 method as well if C-g does not work)

bangedorrunt commented 4 years ago

This is what happened when I pressed C-g after emacs frozen

Screen Shot 2020-10-05 at 4 55 38 pm
progfolio commented 4 years ago

According to: https://www.gnu.org/software/emacs/manual/html_node

Saying y to β€˜Auto-save?’ causes immediate auto-saving of all modified buffers in which auto-saving is enabled. Saying n skips this. This question is omitted if Emacs is in a state where auto-saving cannot be done safely.

Saying y to β€˜Abort (and dump core)?’ causes Emacs to crash, dumping core. This is to enable a wizard to figure out why Emacs was failing to quit in the first place. Execution does not continue after a core dump.

If you answer this question n, Emacs execution resumes. With luck, Emacs will ultimately do the requested quit. If not, each subsequent C-g invokes emergency escape again.

If Emacs is not really hung, just slow, you may invoke the double C-g feature without really meaning to. Then just resume and answer n to both questions, and you will get back to the former state. The quit you requested will happen by and by.

So I'd skip the auto-save unless necessary and skip the core-dump to see if Emacs resumes or is still frozen.

bangedorrunt commented 4 years ago

I did, and I couldn't resume Emacs because it gave me a frozen blank screen. Here is what I could do with debugger. Pls let me know if you need anything I could help. Kapture 2020-10-05 at 17 26 10

progfolio commented 4 years ago

Thank you. It's late for me, so I'll have to look at this tomorrow.

bangedorrunt commented 4 years ago

@progfolio you're welcom. Thank you for your time ❀️

raxod502 commented 4 years ago

Sorry, that looks like you've found a pretty low-level bug which might be difficult to get to the bottom of. It might well be something we could address in straight.el, but the problem is definitely happening way deeper in Emacs internals than any straight.el-specific code.

You could have a look at the straight.el code related to the filesystem watcher. Basically, what enabling that option does is spawn a watchexec subprocess. Apparently, having that subprocess spawned causes the freeze that you are observing. Not sure where to go from there... :/

bangedorrunt commented 4 years ago

@raxod502 thanks for your clarification. If that is the case, I believe it is because I'm using gccemacs which is supposed to be error prone. I could not decide to close this issue or not. So please help me do it if you think so. Have a great day!

raxod502 commented 4 years ago

I guess I'll close it, and if anybody has ideas about how the problem could be something addressable in straight.el then leave a comment and I can re-open.

carrete commented 2 years ago

FYI, I have this problem every time I connect to a clojure repl, either via cider-jack-in or cider-connect. This is on the latest macOS, M1 Pro, Emacs 28.1 (brew install --cask emacs, no native compilation)

raxod502 commented 2 years ago

Interesting, I'm guessing this is unrelated to watchexec (unless it only reproduces when you're using the filesystem watcher?), but could potentially be a manifestation of the same underlying bug.

Unless it only happens when using the filesystem watcher from straight.el, I'd suggest filing a bug against CIDER.

carrete commented 2 years ago

unless it only reproduces when you're using the filesystem watcher?

I uninstalled watchexec and the problem went away

raxod502 commented 2 years ago

Oh yikes, then it does sound potentially related - is it possible for us to reproduce the issue? Ideally using M-x straight-bug-report? If so you could file another issue so it doesn't get lost in this one, and we could try taking a look.

carrete commented 2 years ago

is it possible for us to reproduce the issue?

Yes, I think so. I'm on a new M1 MacBook Pro, macOS 12.3.1, latest emacs (brew install --cask emacs), and latest radian. I created a test project with lein new app straight.el-bug-report. When watchexec is installed, M-x cider-jack-in hangs in this project.

Ideally using M-x straight-bug-report

Unfortunately? this worked. I evaluated:

;; -*- lexical-binding: t -*-
(straight-bug-report
:interactive t
:post-bootstrap
(straight-use-package 'cider))

and then ran M-x cider-jack-in in the same project as above. When I first came across this I disabled packages and settings in radian one-by-one, but this behavior persisted. I gave up after I found I could remove watchexec. I also tried without radian. I only installed cider which worked so I'm not too surprised by this test result.

Is there anything else I should try?

raxod502 commented 2 years ago

That's very odd. I can't say I have any ideas, unfortunately. I tried creating a new Leiningen project per your example, and M-x cider-jack-in worked for me running Radian with watchexec enabled. Not sure where to go next :/

carrete commented 2 years ago

I'm not able to reproduce this any more. Granted I've made configuration changes and cleaned out ~/.emacs.d/ a few times since I last had watchexec installed, but I'm not aware of any changes related to this issue. This once never worked, and now always works. Sorry, I wish I could have been of more help.