greghendershott / racket-mode

Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, packages, and more.
https://www.racket-mode.com/
GNU General Public License v3.0
682 stars 93 forks source link

Back end hangs on macOS Sequoia with Racket before 8.14.04 snapshot 2024-09-24 #722

Open maruks opened 1 month ago

maruks commented 1 month ago

Hello

I am using Emacs 29.4, racket-mode 20240923.1416 and racket v8.14 on Mac OSX Sequoia 15.0. It looks like my Emacs has trouble communicating with racket backend.

I can't open Repl. M-x racket-repl / M-x racket-run-and-switch-to-repl opens an empty buffer.

This error appears in Messages

eldoc error: (error Command (type namespace "") from #<buffer *Racket REPL </>*> to "racket-back-end-/" timed out after 10 seconds) [2 times]

Racket-xp-mode is stuck in running mode. It always shows lambda ( "Getting analysis from Racket Mode back-end and annotating" ).

I can see backend process running:

/Applications/Racket v8.14/bin/racket /Users/maris/.emacs.d/elpa/racket-mode-20240923.1416/racket/main.rkt --use-svg

Config:

(use-package racket-mode
  :mode ("\\.rkt\\'" . racket-mode)
 ;; :hook ((racket-mode . racket-xp-mode))
  :custom
  (racket-program "/Applications/Racket v8.14/bin/racket")
  )

Please copy all of the following lines and paste them into your bug report at https://github.com/greghendershott/racket-mode/issues/.

Package

metadata
(#s(package-desc racket-mode
         (20240923 1416)
         "Racket editing, REPL, and more"
         ((emacs
           (25 1)))
         nil nil "/Users/maris/.emacs.d/elpa/racket-mode-20240923.1416"
         ((:url . "https://www.racket-mode.com/")
          (:authors
           ("Greg Hendershott" . "racket-mode-author@greghendershott.com"))
          (:commit . "7ede89ca36c2b23bd1c646b670a59c18740ec354"))
         nil))
package-archives
(("gnu" . "https://elpa.gnu.org/packages/")
 ("nongnu" . "https://elpa.nongnu.org/nongnu/")
 ("melpa" . "http://melpa.org/packages/")
 ("melpa-stable" . "http://stable.melpa.org/packages/"))
racket--el-source-dir
"/Users/maris/.emacs.d/elpa/racket-mode-20240923.1416/"
racket--rkt-source-dir
"/Users/maris/.emacs.d/elpa/racket-mode-20240923.1416/racket/"

System values

emacs-version
"29.4"
major-mode
help-mode
system-type
darwin
display-graphic-p
t

Buffer values

after-change-functions
nil
before-change-functions
nil
completion-at-point-functions
(tags-completion-at-point-function)
eldoc-documentation-function
eldoc-documentation-default
font-lock-defaults
nil
pre-command-hook
(which-key--hide-popup tooltip-hide)
post-command-hook
(global-font-lock-mode-check-buffers global-eldoc-mode-check-buffers whole-line-or-region-global-mode-check-buffers global-superword-mode-check-buffers mode-local-post-major-mode-change)
post-self-insert-hook
(electric-indent-post-self-insert-function blink-paren-post-self-insert-function)
xref-backend-functions
(etags--xref-backend)

Racket Mode values

racket--cmd-open-p
t
racket-after-run-hook
nil
racket-back-end-configurations
((:directory "/" :racket-program nil :remote-source-dir nil :restart-watch-directories nil :windows nil))
racket-before-run-hook
(racket-ansi-color-context-reset)
racket-browse-url-function
racket-browse-url-using-temporary-file
racket-command-timeout
10
racket-documentation-search-location
"https://docs.racket-lang.org/search/index.html?q=%s"
racket-error-context
medium
racket-expand-hiding
standard
racket-hash-lang-mode-hook
nil
racket-hash-lang-module-language-hook
nil
racket-hash-lang-token-face-alist
((constant . font-lock-constant-face)
 (error . error)
 (other . font-lock-doc-face)
 (keyword . font-lock-keyword-face)
 (hash-colon-keyword . racket-keyword-argument-face)
 (at . font-lock-doc-face))
racket-history-filter-regexp
"\\`\\s *\\'"
racket-imagemagick-props
nil
racket-images-do-not-use-svg
nil
racket-images-inline
t
racket-images-keep-last
100
racket-images-system-viewer
"open"
racket-indent-curly-as-sequence
t
racket-indent-sequence-depth
0
racket-logger-config
((cm-accomplice . warning)
 (GC . info)
 (module-prefetch . warning)
 (optimizer . info)
 (racket/contract . error)
 (racket-mode-debugger . info)
 (sequence-specialization . info)
 (* . fatal))
racket-memory-limit
2048
racket-mode-hook
(smartparens-strict-mode)
racket-module-forms
"\\s(\\(?:module[*+]?\\|library\\)"
racket-pretty-lambda
nil
racket-pretty-print
t
racket-program
"/Applications/Racket v8.14/bin/racket"
racket-repl-buffer-name-function
nil
racket-repl-command-file
"/Users/maris/.emacs.d/racket-mode/repl.rkt"
racket-repl-history-directory
"~/.emacs.d/racket-mode/"
racket-repl-mode-hook
(smartparens-mode)
racket-sexp-comment-fade
0.5
racket-shell-or-terminal-function
racket-shell
racket-show-functions
(racket-show-pseudo-tooltip)
racket-smart-open-bracket-enable
nil
racket-submodules-to-run
((test)
 (main))
racket-use-repl-submit-predicate
nil
racket-xp-add-binding-faces
nil
racket-xp-after-change-refresh-delay
1
racket-xp-eldoc-level
summary
racket-xp-highlight-unused-regexp
"^[^_]"
racket-xp-mode-lighter
(:eval
 (racket--xp-mode-lighter))

Minor modes

enabled
((auto-compression-mode)
 (auto-encryption-mode)
 (blink-cursor-mode)
 (buffer-read-only)
 (column-number-mode)
 (electric-indent-mode)
 (file-name-shadow-mode)
 (font-lock-mode)
 (global-eldoc-mode)
 (global-font-lock-mode)
 (global-superword-mode)
 (indent-tabs-mode)
 (isearch-fold-quotes-mode)
 (line-number-mode)
 (marginalia-mode)
 (mouse-wheel-mode)
 (override-global-mode)
 (persp-mode)
 (projectile-mode)
 (recentf-mode)
 (savehist-mode)
 (semantic-minor-modes-format)
 (server-mode)
 (shell-dirtrack-mode)
 (show-paren-mode)
 (superword-mode)
 (tooltip-mode)
 (transient-mark-mode)
 (vertico-mode)
 (vertico-reverse-mode)
 (which-key-mode)
 (whole-line-or-region-global-mode)
 (whole-line-or-region-local-mode)
 (windmove-mode))
Disabled minor modes
disabled
((abbrev-mode)
 (auto-composition-mode)
 (auto-fill-function)
 (auto-fill-mode)
 (auto-save-mode)
 (auto-save-visited-mode)
 (buffer-face-mode)
 (button-mode)
 (cl-old-struct-compat-mode)
 (comint-fontify-input-mode)
 (compilation-minor-mode)
 (compilation-shell-minor-mode)
 (completion-in-region-mode)
 (consult-notes-denote-mode)
 (consult-notes-org-headings-mode)
 (consult-notes-org-roam-mode)
 (consult-preview-at-point-mode)
 (context-menu-mode)
 (cursor-face-highlight-mode)
 (cursor-intangible-mode)
 (cursor-sensor-mode)
 (dash-fontify-mode)
 (defining-kbd-macro)
 (diff-auto-refine-mode)
 (diff-minor-mode)
 (dired-hide-details-mode)
 (display-line-numbers-mode)
 (eglot--managed-mode)
 (eglot-inlay-hints-mode)
 (eldoc-mode)
 (electric-layout-mode)
 (electric-pair-mode)
 (electric-quote-mode)
 (ert--current-run-stats)
 (flycheck-mode)
 (flymake-mode)
 (global-dash-fontify-mode)
 (global-display-line-numbers-mode)
 (global-flycheck-mode)
 (global-prettify-symbols-mode)
 (global-semantic-highlight-edits-mode)
 (global-semantic-highlight-func-mode)
 (global-semantic-show-parser-state-mode)
 (global-semantic-show-unmatched-syntax-mode)
 (global-semantic-stickyfunc-mode)
 (global-subword-mode)
 (global-visual-line-mode)
 (header-line-indent-mode)
 (horizontal-scroll-bar-mode)
 (hs-minor-mode)
 (ibuffer-auto-mode)
 (ido-everywhere)
 (isearch-mode)
 (jit-lock-debug-mode)
 (lock-file-mode)
 (lost-selection-mode)
 (mail-abbrevs-mode)
 (menu-bar-mode)
 (mix-minor-mode)
 (mml-mode)
 (next-error-follow-minor-mode)
 (org-cdlatex-mode)
 (org-list-checkbox-radio-mode)
 (org-src-mode)
 (org-table-follow-field-mode)
 (org-table-header-line-mode)
 (orgtbl-mode)
 (outline-minor-mode)
 (overwrite-mode)
 (paragraph-indent-minor-mode)
 (prettify-symbols-mode)
 (racket-hash-lang-repl-mode)
 (racket-smart-open-bracket-mode)
 (racket-xp-mode)
 (read-extended-command-mode)
 (semantic-highlight-edits-mode)
 (semantic-highlight-func-mode)
 (semantic-mode)
 (semantic-show-parser-state-mode)
 (semantic-show-unmatched-syntax-mode)
 (semantic-stickyfunc-mode)
 (sh-electric-here-document-mode)
 (shell-highlight-undef-mode)
 (show-smartparens-global-mode)
 (show-smartparens-mode)
 (size-indication-mode)
 (smartparens-global-mode)
 (smartparens-global-strict-mode)
 (smartparens-mode)
 (smartparens-strict-mode)
 (subword-mode)
 (tab-bar-history-mode)
 (tab-bar-mode)
 (temp-buffer-resize-mode)
 (text-scale-mode)
 (tool-bar-mode)
 (transient-resume-mode)
 (treesit-explore-mode)
 (treesit-inspect-mode)
 (undelete-frame-mode)
 (url-handler-mode)
 (use-hard-newlines)
 (vc-dir-git-mode)
 (vertico-buffer-mode)
 (vertico-flat-mode)
 (vertico-grid-mode)
 (vertico-multiform-mode)
 (vertico-unobtrusive-mode)
 (view-mode)
 (visible-mode)
 (visual-line-mode)
 (window-divider-mode)
 (xref-etags-mode)
 (yas-global-mode)
 (yas-minor-mode))

Steps to reproduce:

greghendershott commented 1 month ago

Although I don't yet have any idea what's happening, as an initial quick experiment we could try running the Racket Mode back end directly.

The shell command to run it is basically:

$ racket main.rkt --use-svg

where

So at the shell prompt:

$ /Applications/Racket\ v8.14/bin/racket /Users/maris/.emacs.d/elpa/racket-mode-20240923.1416/racket/main.rkt --use-svg

It might take 5 seconds or so for Racket to load this, then the Racket Mode back end should print:

(ready )

At this point you can pretend to be the Emacs front end of Racket Mode, and enter commands and see responses.

Try typing the following and hit ENTER:

(1 nil path)

It should instantly print a response like this (though the path will differ for you):

(1 ok "/home/greg/src/elisp/racket-mode/racket/" )

Then you can just C-c out of it.

  1. Does all that work for you in a macOS shell?

  2. How about in an M-x shell Emacs shell?

greghendershott commented 1 month ago

Some other debugging ideas/comments:

For a plain old local back end, Emacs is just running a process and using a plain old pipe for I/O. Various Racket Mode commands go to the back end's input, and the back end outputs command responses and various unsolicited notifications, which end up in that racket-back-end-/ buffer until the front end processes them. The "wire protocol" is Emacs s-expressions.

Of course the word "just" does a lot of work in that sentence, but typically this has worked without any drama for many years. I wonder what's going on, here! I'm sorry you're having a problem but I'm interested in figuring this out!

FWIW I'm also using Emacs 29.4, albeit built for Linux.

Although I have a Mac for testing, it's not yet upgraded to Sequoia. I will try that myself, but it may take me a day or two to find time to do the upgrade process etc.

distractedlambda commented 1 month ago

Different user here having the same issue, with a very similar software setup (critically, including the macOS Sequoia part).

  1. Does all that work for you in a macOS shell?

I get the (ready ), but after entering (1 nil path) it hangs at 100% CPU usage (and doesn't respect ctrl+c).

greghendershott commented 1 month ago

@distractedlambda Although I think you were clear, just to make sure: Is that symptom when you try in Terminal.app? Or Emacs *shell* buffer? Or both?

greghendershott commented 1 month ago

Unfortunately I can't reproduce this on macOS Monterrey, which is the newest this 2017 Macbook 9,1 can take.

Using Terminal.app (with 1. Racket 8.14 installed, and, 2. git clone of this project to ~/src/elisp/racket-mode):

Gregs-Macbook:~ /Applications/Racket_v8.14/bin/racket /Users/greg/src/elisp/racket-mdoe/racket/main.rkt --use-svg
(ready )              # output
(1 nil path)          # my input
(1 ok "/Users/greg" ) # output

and C-c works to exit.

@distractedlambda I think this is equivalent to what you're doing -- but you don't get the (1 ok ___) response and C-c doesn't work. Correct?


On startup, it does use delay/thread to do load-collections-xref and make-blueboxes-cache.

Otherwise, it goes into a main command loop where it reads an Emacs Lisp s-expression from stdin, and uses a fresh thread to run each command.

I'm trying to imagine how macOS Sequoia per se would change something in Racket itself to make this behave differently? Would that in fact be an issue in Racket 8.14 itself??


Although I'm willing to buy a newer-enough MacBook Air or Mini to run Sequoia, I probably can't within the next few days. :disappointed:

soegaard commented 1 month ago

I get this on a 2019 Intel Mac running Sequoia.

% /Applications/Racket\ v8.14.0.4/bin/racket racket-mode/racket/main.rkt --use-svg
(ready )
(1 nil path)
(1 ok "/Users/soegaard/tmp/" )
(logger "[  debug] racket-mode:    0 cpu |    0 real |    0 gc :: '(1 \"*\" (path))\n" )
^Cuser break
  context...:
   /Users/soegaard/tmp/racket-mode/racket/command-server.rkt:64:0: command-server-loop
   body of (submod "/Users/soegaard/tmp/racket-mode/racket/main.rkt" main)

Note: I used the snapshot version from today and this fix.

https://github.com/racket/gui/commit/d8ee912321da958a5a9eec7eee27a5f93dd4d1bd

soegaard commented 1 month ago

I realized that I also have 8.14.0.2 installed. Here I see the same behavior as @distractedlambda .

distractedlambda commented 1 month ago

I'm using an ARM Mac FWIW, but this is definitely sounding like a Sequoia issue.

distractedlambda commented 1 month ago

I'll try a snapshot build of Racket when I get some time to do so (may not be today).

greghendershott commented 1 month ago

@soegaard Brilliant thank you so much.

So IIUC @distractedlambda and @maruks you can resolve this by using, not the Racket 8.14 release, but a snapshot from today 2024-09-24 or later.

Next Racket release might be an 8.14.1 update, or 8.15 in some months.

maruks commented 1 month ago

thank you, snapshot version works for me

greghendershott commented 1 month ago

Already the back end checks early for the Racket version, and exits if not at least a minimum supported (currently 6.12).

It occurred to me I could add a check for running on macOS Sequoia 15.0 or newer, and in that case require at least Racket 8.14.04.

So I merged that. Although I couldn't test on Sequoia, I tested on Sonoma and saw the correct version string. So I think this is safe; I don't want to be too clever and have it backfire. Assuming it works correctly people should get some clear early feedback. Also I'll tag this issue with "FAQ" and pin it, for awhile.

distractedlambda commented 1 month ago

Just for completeness, I can confirm that today's snapshot version works for me as well.

soegaard commented 1 month ago

FWIW The fix in

https://github.com/racket/gui/commit/d8ee912321da958a5a9eec7eee27a5f93dd4d1bd

simply moves the definition of wake-evt and socket_callback up before they are used.

This fix also works on Racket 8.12.

greghendershott commented 1 month ago

FWIW The fix in

racket/gui@d8ee912

simply moves the definition of wake-evt and socket_callback up before they are used.

This fix also works on Racket 8.12.

Good to know. So if someone wants to "backport" this, they can do so -- even in a very casual way by finding that file, editing it, and saving it. It would be nice to raco make that, for speed, but not strictly necessary. Caveat: I say this based on past experience making such casual, experimental hacks -- but I haven't tried this one specifically. Of course there are less-casual ways involving git and applying patches, to get the same result.

tomtitchener commented 3 weeks ago

Same problem (Emacs, racket-mode, ARM, Sequoia 15.0.1), below.

But now it's 10/24, I no longer see snapshot from today 2024-09-24 or later, but racket-8.15.0.2.

Is it ok to just run 8.15.0.2 or is there a way for me to hunt-down 18.14.02 ... or are they actually the same thing ... :)

Thanks TT

{racket-back-end-/-stderr} internal error: attempt to deschedule the current thread in atomic mode context...: /opt/homebrew/Cellar/minimal-racket/8.14/share/racket/collects/racket/system.rkt:174:0: do-system*/exit-code /Users/tomtitchener/.emacs.d/elpa/racket-mode-20241018.1545/racket/main.rkt:22:0: macos-sequoia-or-newer? /Users/tomtitchener/.emacs.d/elpa/racket-mode-20241018.1545/racket/main.rkt:34:2 body of (submod "/Users/tomtitchener/.emacs.d/elpa/racket-mode-20241018.1545/racket/main.rkt" main)

greghendershott commented 3 weeks ago

As far as I know you simply need any version of Racket that is at least 8.14.04. The 8.15.0.2 snapshot should be fine.

The 8.15 official release is coming soon (some small number of weeks, AFAIK?), which should also be fine.

tomtitchener commented 3 weeks ago

Got it, many thanks! This is a dynamite package, especially with emacs integration.