emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
613 stars 160 forks source link

R session buffer hangs while waiting for help to show up #1075

Closed japhir closed 3 years ago

japhir commented 3 years ago

I thought this was the same issue as https://github.com/emacs-ess/ESS/issues/1062, but perhaps not.

When I start a new R session, and I type e.g. ?data.frame, I get an Retrieving RDS aliases...done message in the minibuffer, but other than that it keeps hanging!

When I C-g a couple of times, the help buffer shows up but the ? data.frame line is still running, and keeps running even after I q on the help buffer.

I then have to C-c on the R terminal and I'm back to normal. Perhaps the last bit is irrelevant because q doesn't appear to kill the buffer, so it may make sense to have the help command in the R session still run. If I manually kill the help buffer, it also doesn't unfreeze the interactive session.

This time, when I tried to run the previous command again (M-p) History item 1, it shows up but now the whole emacs session seems t hang until I repeatedly hit C-g again. Then tried again and it worked normally this time. Running another command, e.g. ? tibble::tibble repeats the process.

lionel- commented 3 years ago

What version of ESS do you have installed?

If the latest, can you please evaluate this, trigger the hang, and report the log at the hang point:

(let ((fns (union (all-completions "ess-" obarray)
                  (all-completions "inferior-ess-" obarray))))
  (dolist (fn fns)
    (trace-function (intern fn))))
japhir commented 3 years ago

I've just updated, but the problem persists.

output of M-x ess-version: ess-version: 18.10.3snapshot [elpa: 20201217.1440] (loaded from /home/japhir/.emacs.d/elpa/ess-20201217.1440/)

I would like to run that code to help debug this but I get an error when evaluating it:

Debugger entered--Lisp error: (void-function union)
  (union (all-completions "ess-" obarray) (all-completions "inferior-ess-" obarray))
  (let ((fns (union (all-completions "ess-" obarray) (all-completions "inferior-ess-" obarray)))) (let ((--dolist-tail-- fns) fn) (while --dolist-tail-- (setq fn (car --dolist-tail--)) (trace-function (intern fn)) (setq --dolist-tail-- (cdr --dolist-tail--)))))
  eval((let ((fns (union (all-completions "ess-" obarray) (all-completions "inferior-ess-" obarray)))) (let ((--dolist-tail-- fns) fn) (while --dolist-tail-- (setq fn (car --dolist-tail--)) (trace-function (intern fn)) (setq --dolist-tail-- (cdr --dolist-tail--))))) nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

Here's what the Messages buffer captures when I run into the issue:

Forming completions for .GlobalEnv...done
Forming completions for ESSR...done
Forming completions for package:stats...done
Forming completions for package:graphics...done
Forming completions for package:grDevices...done
Forming completions for package:utils...done
Forming completions for package:datasets...done
Forming completions for package:devtools...done
Forming completions for package:usethis...done
Forming completions for package:methods...done
Forming completions for Autoloads...done
Forming completions for package:base...done
Retrieving RDS aliases...done
Quit 
lionel- commented 3 years ago

What if you replace union by cl-union?

lionel- commented 3 years ago

oh this should work too since the sets are disjoints:

(let ((fns (append (all-completions "ess-" obarray)
                   (all-completions "inferior-ess-" obarray))))
    (dolist (fn fns)
      (trace-function (intern fn))))

I'll add an ess--trace function to ESS to do this more easily.

japhir commented 3 years ago

Ok, that's a lot of output! So much so that I can't even paste it as a github comment...

And it doesn't stop appending to it, so it keeps growing bigger and bigger and I can't just select the relevant part. Pastebins are also overflowed. :(

Ah, I can upload files here as well. It was at line 8074 when it was hanging, waiting for me to C-g and make my session interactive again.

ess-debug.txt

lionel- commented 3 years ago

@japhir Sorry I haven't had time to look into this yet.

We have pushed some fixes related to background help commands, could you upgrade to the latest MELPA version and see if that helped please?

japhir commented 3 years ago

No worries! The problem appears to have been resolved with the latest updates!

gavinsimpson commented 3 years ago

Should this be fixed in 20210117.1706? As I'm seeing exactly this behaviour in ESS after upgrading to this version. I see the following in the Messages buffer:

Retrieving RDS aliases...done
ess-command: Timeout during background ESS command ‘names(formals(gam(formula,family=gaussian(),data=list))’

The help page is opened but the buffer isn't raised to be visible, and the R prompt is not displayed (you can hit return in the R console buffer and the prompt displays).

japhir commented 3 years ago

Hmm yeah this seems to have regressed, I now get all of these error messages when I M-x R

Cannot read history file /home/japhir/SurfDrive/bibliography/notes/daily/.Rhistory
Messages while loading ESSR: + + + Error in file(filename, "r", encoding = encoding) : 
  cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
  cannot open file ’/home/japhir/.emacs.d/elpa/ess-20210113.915/etc/ESSR/R/.load.R’: No such file or directory

and then run ?data.frame

if: Timeout during background ESS command ‘options(STERM='iESS', str.dendrogram.last="'", editor='emacsclient', show.error.locations=TRUE)’
if: Timeout during background ESS command ‘options(width=238, length=99999)’
if: Timeout during background ESS command ‘as.character(utils::help('data.frame'))’
if: Timeout during background ESS command ‘options(width=238, length=99999)’
lionel- commented 3 years ago

There is a problem with your ESSR installation @japhir.

lionel- commented 3 years ago

@gavinsimpson This command is not complete (seems the trailing parenthesis is missing), this is a different bug. Can you open another issue with a reprex please?

gavinsimpson commented 3 years ago

@lionel- I will certainly do that, but how do I create a reproducible example for ESS? I'm literally just typing ?gam to view the help.

lionel- commented 3 years ago

?gam is the reprex :)

lionel- commented 3 years ago

I can't reproduce @gavinsimpson, please make sure you attach the minimal amount of packages with library() to be able to reproduce this. You might want to try on a fresh Emacs instance as well because ESS may cache the results of ?. The reproducibility might also be dependent on the package versions because this sort of bugs arises while parsing .Rd files.

Edit: Nevermind, I was trying with library(gam) but can now reproduce with library(mgcv).

japhir commented 3 years ago

There is a problem with your ESSR installation @japhir.

ah yeah, apparently I had some remnant of an orphaned AUR package (or perhaps emacs-ess-git) installed...

:load-path "/usr/share/emacs/site-lisp/ess"

After commenting that out it seems to do okay again.