Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emacs sometimes gets stuck after it is idle in a pdf-tools buffer #278

Open
benthamite opened this issue May 1, 2024 · 15 comments
Open

Comments

@benthamite
Copy link

benthamite commented May 1, 2024

Describe the bug

When I leave the computer and the current buffer is displaying a PDF file with pdf-tools, upon returning to it hours later I sometimes have to run pkill -SIGUSR2 Emacs. In those cases, the debugger returns a backtrace like this:

Debugger entered--entering a function:
* help-command-error-confusable-suggestions((quit) "" nil)
recursive-edit()
debug(lambda)
* help-command-error-confusable-suggestions((quit) "" nil)
recursive-edit()
debug(lambda)
* substitute-command-keys("Quit")
pdf-info-query(pagesize "/Users/pablostafforini/Google Drive/library-pdf/Borges1974ObrasCompletas1923.pdf" 1048)
pdf-info-pagesize(1048)
pdf-cache-pagesize(1048)
pdf-view-desired-image-size(1048 #<window 3 on Borges1974ObrasCompletas1923.pdf>)
pdf-view-create-page(1048 #<window 3 on Borges1974ObrasCompletas1923.pdf>)
pdf-view-display-page(1048 #<window 3 on Borges1974ObrasCompletas1923.pdf>)
pdf-view-redisplay(#<window 3 on Borges1974ObrasCompletas1923.pdf>)
pdf-view-maybe-redisplay-resized-windows()
pdf-view-redisplay-some-windows()

Steps to Reproduce the behaviour
The behavior is not easily reproducible because it happens erratically and only after long periods of inactivity.

What is the expected behaviour?
Emacs does not get stuck.

Desktop
Please complete the following information:

  • OS: macOS Sonoma 14.2.1
  • Emacs Version: GNU Emacs 29.3 (build 2, aarch64-apple-darwin23.2.0, NS appkit-2487.30 Version 14.2.1 (Build 23C71)) of 2024-04-26
  • Poppler Version: stable 24.04.0 (bottled), HEAD

Your pdf-tools install
Please complete the following information:

  • pdf-tools Version:
     Status: Available from nongnu -- Install
    Archive: nongnu
    Version: 1.1.0
     Commit: a9c9a12c3ecf2005fa641059368ac8284f507620
    Summary: Support library for PDF documents
   Requires: emacs-26.3, tablist-1.0, let-alist-1.0.4
    Website: https://github.com/vedang/pdf-tools/
   Keywords: files multimedia 
 Maintainer: Vedang Manerikar <[email protected]>
     Author: Andreas Politz <[email protected]>
  • pdf-tools customization / configuration that you use:
(use-package pdf-tools
  :defer 10
  :mode ("\\.pdf\\'" . pdf-view-mode)
  :config
  (setq pdf-view-use-scaling t)
  (setq pdf-view-use-imagemagick nil)
  (setq pdf-view-resize-factor 1.1)
  (setq pdf-annot-default-annotation-properties
        '((t
           (label . user-full-name))
          (text
           (color . "#ff0000")
           (icon . "Note"))
          (highlight
           (color . "LightBlue2"))
          (underline
           (color . "blue"))
          (squiggly
           (color . "orange"))
          (strike-out
           (color . "red"))))

  (pdf-tools-install t)

  (add-hook 'pdf-tools-enabled-hook #'pdf-view-fit-page-to-window)
  (add-hook 'pdf-tools-enabled-hook #'sow-mode)

  :general
  ((pdf-view-mode-map pdf-annot-minor-mode-map pdf-history-minor-mode-map)
   "e" 'pdf-annot-add-highlight-markup-annotation
   "j" 'pdf-view-goto-page
   "k" 'pdf-view-previous-line-or-previous-page
   "l" 'pdf-view-next-line-or-next-page
   "H-c" 'pdf-view-kill-ring-save
   "A-u" 'pdf-view-midnight-minor-mode))
@aikrahguzar
Copy link

I have seen Emacs hang with pdf-tools but it has been due to some interaction with url-queue that I don't understand. My best guess is there is some race condition somewhere in the tq library that pdf-tools use and if pdf-info-query always shows up at the top of backtrace, you are probably seeing another manifestation of the same thing.

You can try disabling pdf-cache-prefetch-minor-mode and see if the hangs persist. This helped me, but since the hangs happen after inactivity (prefetching should be done by then) I doubt that it will help your case.

Another thing to figure out is why is the size of the window changing (likely when the Emacs frame gets focus). Do you have any customizations for after-focus-change-function or focus-in-hook?

@benthamite
Copy link
Author

Thanks. I have disabled pdf-cache-prefetch-minor-mode and will report back if I notice any change.

I don't have any customizations for after-focus-change-function or focus-in-hook.

@aikrahguzar
Copy link

Assuming pdf-view-maybe-redisplay-resized-windows always shows up in the backtrace, one thing to try will be to resize a pdf window manually using mouse or keybind and see if you can reproduce the issue that way.

@goofansu
Copy link

goofansu commented Aug 6, 2024

The issue can be reproduced by opening a PDF and M-x toggle-frame-fullscreen. Resize using mouse or Rectangle keybindings doesn't stuck Emacs.

Environment:

  • macOS Version 14.6 (23G80)
  • GNU Emacs 29.3 (build 1, aarch64-apple-darwin22.6.0, NS appkit-2299.70 Version
    13.5.2 (Build 22G91))
  • (setq ns-use-native-fullscreen nil)

A workaround is to (setq ns-use-native-fullscreen t).

Screencast
CleanShot.2024-08-06.at.22.12.51.mp4

@aikrahguzar
Copy link

The issue can be reproduced by opening a PDF and M-x toggle-frame-fullscreen. Resize using mouse or Rectangle keybindings doesn't stuck Emacs.

Environment:

* macOS Version 14.6 (23G80)

* GNU Emacs 29.3 (build 1, aarch64-apple-darwin22.6.0, NS appkit-2299.70 Version
  13.5.2 (Build 22G91))

* `(setq ns-use-native-fullscreen nil)`

A workaround is to (setq ns-use-native-fullscreen t).
Screencast
CleanShot.2024-08-06.at.22.12.51.mp4

Does it happen with just emacs -Q and pdf-tools-mode? And can you please produce a backtrace? (Do M-x toggle-debug-on-quit RET before full screening. C-g will produce a backtrace if it works. If it doesn't pkill -SIGUSR2 emacs should do the trick.)

@goofansu
Copy link

@aikrahguzar I tried to get the backtrace according to your methods.

C-g cannot recover the Emacs from frozen state, then I tried pkill -SIGUSR2 Emacs (I'm using the Emacs.app on macOS). It kills the Emacs but I don't know where to get the backtrace.

@benthamite
Copy link
Author

benthamite commented Aug 30, 2024

@goofansu, pkill -SIGUSR2 Emacs should both kill the process and create an associated backtrace. Did you look for it in the list of buffers (C-x b *Backtrace*)?

@goofansu
Copy link

goofansu commented Aug 30, 2024

@benthamite I can only see a transparent *Backtrace* buffer in Mission Control after using the command, see the video: https://share.cleanshot.com/GPdZtJWbDHZvsGfxdqxM

@benthamite
Copy link
Author

benthamite commented Aug 30, 2024

@goofansu, what appears to be going on is that pkill -SIGUSR2 Emacs didn’t succeed in killing the relevant process, so Emacs continues to be unresponsive. You can try the "nuclear option" while true; do pkill -SIGUSR2 Emacs; done and see if this does the trick. You may also want to try a combination of pkill -SIGUSR2 Emacs, hitting ESC repeatedly and wait a few minutes, which in my experience sometimes eventually restores the Emacs session and triggers the backtrace. Otherwise, this may be one of those cases when restarting is the only option, in which case producing a backtrace won’t be possible.

@benthamite
Copy link
Author

(Also, before you do any of the above, you may want to run pkill -SIGUSR2 Emacs when Emacs is working normally, just to test if this command has its intended effect in normal circumstances.)

@goofansu
Copy link

goofansu commented Aug 30, 2024

(Also, before you do any of the above, you may want to run pkill -SIGUSR2 Emacs when Emacs is working normally, just to test if this command has its intended effect in normal circumstances.)

@benthamite It works in normal circumstance: CleanShot 2024-08-30 at 23 57 59

Then I made Emacs frozen like #278 (comment), and run while true; do pkill -SIGUSR2 Emacs; done in bash shell, Emacs just crashed and I still cannot visit the *Backtrace* buffer.

You may also want to try a combination of pkill -SIGUSR2 Emacs, hitting ESC repeatedly and wait a few minutes, which in my experience sometimes eventually restores the Emacs session and triggers the backtrace.

I'll try this combination.

@goofansu
Copy link

@benthamite I found I can select and run command in the transparent *Backtrace* buffer although I cannot see the content, but unfortunately the content I copied doesn't help:

Debugger entered--entering a function:
* help-command-error-confusable-suggestions((quit) "" nil)

CleanShot 2024-08-31 at 00 26 55

@benthamite
Copy link
Author

benthamite commented Aug 30, 2024

Mmh, weird: I don’t quite understand what’s going on.

In any case, thank you for your efforts in helping us debug this issue.

@aikrahguzar
Copy link

@goofansu I don't have a good idea on how to proceed with debugging. I think running under gdb might help but I don't know how to go about that. If you can please post a question about how to debug this situation to help-gnu-emacs. You will likely get response for Emacs maintainers and people on that list are very helpful.

@goofansu
Copy link

@aikrahguzar Ok, I will. Thank you for the guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants