Reilstein
Reilstein

Reputation: 1252

Rstudio rsession hangs when editing file

I've been toying with this issue for hours now and I think I finally have it reproducible.

When I start a new Rstudio session everything works fine and there is no issue. I can even load objects and execute code fine.

The problem arises when I edit the current file. As soon as I edit the file, I can no longer execute commands and when I look at CPU usage with top it shows that rsession is using 100% CPU and it never stops. during this time I can continue to edit the file and the Rstudio GUI appears to work fine, but the code execution is frozen. I also cannot save files at that point either.

EDIT: The document type I am trying to edit is an .Rmd markdown document. I just tried running the same code in a non-markdown R script and it ran fine. The issue must be related to markdown somehow.

EDIT2: ^^ nevermind, the issue remains even when not an .Rmd file. After saving the script as a normal .R script it then caused the rsession to hang again.

EDIT3: I forgot to mention that this is a recent occurrence, likely induced by updated R version , Rstudio version, or system library. Yesterday I Was able to edit this script without any issues in Rstudio. I updated Rstudio this week but did not see this issue until several days after. I updated my system shortly after which likely also updated the R version. I'm just struggling to understand how this is causing the present issue.

EDIT4: Found the piece of code causing the error, posted below.

Backtrace of rsession when error occurred (after editing file)

Thread 1 "rsession" received signal SIGTERM, Terminated.
0x00007fbd0cb5ab38 in ?? () from /usr/lib/R/lib/libR.so
(gdb) backtrace
#0  0x00007fbd0cb5ab38 in ?? () from /usr/lib/R/lib/libR.so
#1  0x00007fbd0cb71196 in ?? () from /usr/lib/R/lib/libR.so
#2  0x00007fbd0cb72499 in ?? () from /usr/lib/R/lib/libR.so
#3  0x00007fbd0cb6ae8c in Rf_eval () from /usr/lib/R/lib/libR.so
#4  0x00007fbd0cb6b3b9 in ?? () from /usr/lib/R/lib/libR.so
#5  0x00007fbd0cb6b878 in ?? () from /usr/lib/R/lib/libR.so
#6  0x00007fbd0cb6132d in ?? () from /usr/lib/R/lib/libR.so
#7  0x00007fbd0cb6aa88 in Rf_eval () from /usr/lib/R/lib/libR.so
#8  0x00007fbd0cb6b3b9 in ?? () from /usr/lib/R/lib/libR.so
#9  0x00007fbd0cb6b878 in ?? () from /usr/lib/R/lib/libR.so
#10 0x00007fbd0cb6132d in ?? () from /usr/lib/R/lib/libR.so
#11 0x00007fbd0cb6aa88 in Rf_eval () from /usr/lib/R/lib/libR.so
#12 0x00007fbd0cb6b3b9 in ?? () from /usr/lib/R/lib/libR.so
#13 0x00007fbd0cb6b878 in ?? () from /usr/lib/R/lib/libR.so
#14 0x00007fbd0cb6132d in ?? () from /usr/lib/R/lib/libR.so
#15 0x00007fbd0cb6aa88 in Rf_eval () from /usr/lib/R/lib/libR.so
#16 0x00007fbd0cb6b3b9 in ?? () from /usr/lib/R/lib/libR.so
#17 0x00007fbd0cb6b878 in ?? () from /usr/lib/R/lib/libR.so
#18 0x00007fbd0cb6132d in ?? () from /usr/lib/R/lib/libR.so
#19 0x00007fbd0cb6aa88 in Rf_eval () from /usr/lib/R/lib/libR.so
#20 0x00007fbd0cb6b3b9 in ?? () from /usr/lib/R/lib/libR.so
#21 0x00007fbd0cb6b878 in ?? () from /usr/lib/R/lib/libR.so
#22 0x00007fbd0cb6132d in ?? () from /usr/lib/R/lib/libR.so
#23 0x00007fbd0cb6aa88 in Rf_eval () from /usr/lib/R/lib/libR.so
#24 0x00007fbd0cb6ceaf in ?? () from /usr/lib/R/lib/libR.so
#25 0x00007fbd0cb623c0 in ?? () from /usr/lib/R/lib/libR.so
#26 0x00007fbd0cb6aa88 in Rf_eval () from /usr/lib/R/lib/libR.so
#27 0x00007fbd0cb6ceaf in ?? () from /usr/lib/R/lib/libR.so
#28 0x00007fbd0cb623c0 in ?? () from /usr/lib/R/lib/libR.so
#29 0x00007fbd0cb6aa88 in Rf_eval () from /usr/lib/R/lib/libR.so
#30 0x00007fbd0cb6ceaf in ?? () from /usr/lib/R/lib/libR.so
#31 0x00007fbd0cb623c0 in ?? () from /usr/lib/R/lib/libR.so
#32 0x00007fbd0cb6aa88 in Rf_eval () from /usr/lib/R/lib/libR.so
#33 0x00007fbd0cb6ceaf in ?? () from /usr/lib/R/lib/libR.so
#34 0x00007fbd0cb623c0 in ?? () from /usr/lib/R/lib/libR.so
#35 0x00007fbd0cb6aa88 in Rf_eval () from /usr/lib/R/lib/libR.so
#36 0x00007fbd0cb6ceaf in ?? () from /usr/lib/R/lib/libR.so
#37 0x00007fbd0cb6ac56 in Rf_eval () from /usr/lib/R/lib/libR.so
#38 0x00007fbd0cb1a58e in ?? () from /usr/lib/R/lib/libR.so
---Type <return> to continue, or q <return> to quit---
#39 0x00007fbd0cb1bac1 in R_ToplevelExec () from /usr/lib/R/lib/libR.so
#40 0x00007fbd0cb1bb09 in R_tryEval () from /usr/lib/R/lib/libR.so
#41 0x0000000000de4189 in rstudio::r::exec::(anonymous namespace)::evaluateExpressionsUnsafe(SEXPREC*, SEXPREC*, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::(anonymous namespace)::EvalType) [clone .constprop.57] ()
#42 0x0000000000de5d55 in rstudio::r::exec::evaluateString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, SEXPREC**, rstudio::r::sexp::Protect*) ()
#43 0x000000000070c85f in rstudio::session::modules::rparser::(anonymous namespace)::resolveObjectAssociatedWithCall(rstudio::core::r_util::token_cursor::RTokenCursor, rstudio::r::sexp::Protect*, bool, bool*) [clone .constprop.1377] ()
#44 0x000000000070e3f7 in rstudio::session::modules::rparser::(anonymous namespace)::mightPerformNonstandardEvaluation(rstudio::core::r_util::token_cursor::RTokenCursor const&, rstudio::session::modules::rparser::ParseStatus&) ()
#45 0x0000000000997dd2 in rstudio::session::modules::rparser::doParse(rstudio::core::r_util::token_cursor::RTokenCursor&, rstudio::session::modules::rparser::ParseStatus&) ()
#46 0x000000000099a320 in rstudio::session::modules::rparser::parse(rstudio::core::FilePath const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, rstudio::session::modules::rparser::ParseOptions const&) ()
#47 0x00000000008a9e65 in rstudio::session::modules::diagnostics::parse(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, rstudio::core::FilePath const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) ()
#48 0x00000000008adf66 in rstudio::session::modules::diagnostics::(anonymous namespace)::lintRSourceDocument(rstudio::core::json::JsonRpcRequest const&, rstudio::core::json::JsonRpcResponse*) ()
#49 0x0000000000783a0f in rstudio_boost::detail::function::function_invoker2<rstudio::core::Error (*)(rstudio::core::json::JsonRpcRequest const&, rstudio::core::json::JsonRpcResponse*), rstudio::core::Error, rstudio::core::json::JsonRpcRequest const&, rstudio::core::json::JsonRpcResponse*>::invoke(rstudio_boost::detail::function::function_buffer&, rstudio::core::json::JsonRpcRequest const&, rstudio::core::json::JsonRpcResponse*) ()
#50 0x0000000000c5f898 in rstudio::core::json::(anonymous namespace)::runSynchronousFunction(rstudio_boost::function<rstudio::core::Error (rstudio::core::json::JsonRpcRequest const&, rstudio::core::json::JsonRpcResponse*)> const&, rstudio::core::json::JsonRpcRequest const&, rstudio_boost::function<void (rstudio::core::Error const&, rstudio::core::json::JsonRpcResponse*)> const&) ()
#51 0x00000000007e46f9 in rstudio::session::rpc::handleRpcRequest(rstudio::core::json::JsonRpcRequest const&, rstudio_boost::shared_ptr<rstudio::session::HttpConnection>, rstudio::session::http_methods::ConnectionType) ()
#52 0x00000000007e99bb in rstudio::session::http_methods::handleConnection(rstudio_boost::shared_ptr<rstudio::session::HttpConnection>, rstudio::session::http_methods::ConnectionType) ()
#53 0x00000000007ebc8b in rstudio::session::http_methods::waitForMethod(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rstudio_boost::function<void ()> const&, rstudio_boost::function<bool ()> const&, rstudio::core::json::JsonRpcRequest*) ()
#54 0x0000000000754b13 in rstudio::session::console_input::rConsoleRead(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, rstudio::r::session::RConsoleInput*) ()
#55 0x0000000000e22cba in rstudio::r::session::RReadConsole(char const*, unsigned char*, int, int) ()
#56 0x00007fbd0cb9431c in Rf_ReplIteration () from /usr/lib/R/lib/libR.so
---Type <return> to continue, or q <return> to quit---
#57 0x00007fbd0cb94811 in ?? () from /usr/lib/R/lib/libR.so
#58 0x00007fbd0cb948c8 in run_Rmainloop () from /usr/lib/R/lib/libR.so
#59 0x0000000000e4098f in rstudio::r::session::runEmbeddedR(rstudio::core::FilePath const&, rstudio::core::FilePath const&, bool, bool, SA_TYPE, rstudio::r::session::Callbacks const&, rstudio::r::session::InternalCallbacks*) ()
#60 0x0000000000e1ef3f in rstudio::r::session::run(rstudio::r::session::ROptions const&, rstudio::r::session::RCallbacks const&) ()
#61 0x0000000000718a83 in main ()

rstudio-diagnostics:

[1] "1.1.383"

$R
[1] "/usr/bin/R"

$pdflatex
[1] "/usr/bin/pdflatex"

$bibtex
[1] "/usr/bin/bibtex"

$gcc
[1] "/usr/bin/gcc"

$git
[1] "/usr/bin/git"

$svn
[1] ""

R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C 
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] compiler_3.4.2 tools_3.4.2 yaml_2.1.14

SysInfo:
sysname release 
"Linux" "4.4.0-97-generic" 
version nodename 
"#120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017" "reilly-Precision-7510" 
machine login 
"x86_64" "unknown" 
user effective_user 
"reilly" "reilly"

R Version:
_ 
platform x86_64-pc-linux-gnu 
arch x86_64 
os linux-gnu 
system x86_64, linux-gnu 
status 
major 3 
minor 4.2 
year 2017 
month 09 
day 28 
svn rev 73368 
language R 
version.string R version 3.4.2 (2017-09-28)
nickname Short Summer 
$CLICOLOR_FORCE
[1] "1"

$CLUTTER_IM_MODULE
[1] "xim"

$COMPIZ_BIN_PATH
[1] "/usr/bin/"

$COMPIZ_CONFIG_PROFILE
[1] "ubuntu"

$DBUS_SESSION_BUS_ADDRESS
[1] "unix:abstract=/tmp/dbus-O9bssVywYW"

$DEFAULTS_PATH
[1] "/usr/share/gconf/ubuntu.default.path"

$DERBY_HOME
[1] "/usr/lib/jvm/java-8-oracle/db"

$DESKTOP_SESSION
[1] "ubuntu"

$DISPLAY
[1] ":0"

$EDITOR
[1] "vi"

$GDM_LANG
[1] "en_US"

$GDMSESSION
[1] "ubuntu"

$GIO_LAUNCHED_DESKTOP_FILE
[1] "/usr/share/applications/rstudio.desktop"

$GIO_LAUNCHED_DESKTOP_FILE_PID
[1] "4600"

$GIT_ASKPASS
[1] "rpostback-askpass"

$GNOME_DESKTOP_SESSION_ID
[1] "this-is-deprecated"

$GNOME_KEYRING_CONTROL
[1] ""

$GNOME_KEYRING_PID
[1] ""

$GPG_AGENT_INFO
[1] "/home/reilly/.gnupg/S.gpg-agent:0:1"

$GTK2_MODULES
[1] "overlay-scrollbar"

$GTK_IM_MODULE
[1] "ibus"

$GTK_MODULES
[1] "gail:atk-bridge:unity-gtk-module"

$HOME
[1] "/home/reilly"

$IM_CONFIG_PHASE
[1] "1"

$INSTANCE
[1] ""

$J2REDIR
[1] "/usr/lib/jvm/java-8-oracle/jre"

$J2SDKDIR
[1] "/usr/lib/jvm/java-8-oracle"

$JAVA_HOME
[1] "/usr/lib/jvm/java-8-oracle"

$JOB
[1] "unity-settings-daemon"

$LANG
[1] "en_US.UTF-8"

$LANGUAGE
[1] "en_US"

$LD_LIBRARY_PATH
[1] "/usr/lib/R/lib:/home/bmreilly/software/ncbi/lib64:/home/reilly/software/ncbi/lib64::::/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server:/home/bmreilly/software/ncbi/lib64:/home/reilly/software/ncbi/lib64:"

$LN_S
[1] "ln -s"

$LOGNAME
[1] "reilly"

$MAKE
[1] "make"

$MANDATORY_PATH
[1] "/usr/share/gconf/ubuntu.mandatory.path"

$NGS_LIBDIR
[1] "/home/bmreilly/software/ncbi/lib64"

$PAGER
[1] "/usr/bin/pager"

$PATH
[1] "/home/reilly/software/ncbi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin"

$PWD
[1] "/home/reilly"

$QT4_IM_MODULE
[1] "xim"

$QT_ACCESSIBILITY
[1] "1"

$QT_IM_MODULE
[1] "ibus"

$QT_LINUX_ACCESSIBILITY_ALWAYS_ON
[1] "1"

$QT_QPA_PLATFORMTHEME
[1] "appmenu-qt5"

$R_BROWSER
[1] "xdg-open"

$R_BZIPCMD
[1] "/bin/bzip2"

$R_DOC_DIR
[1] "/usr/share/R/doc"

$R_GZIPCMD
[1] "/bin/gzip -n"

$R_HOME
[1] "/usr/lib/R"

$R_INCLUDE_DIR
[1] "/usr/share/R/include"

$R_LIBS_SITE
[1] "/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library"

$R_LIBS_USER
[1] "~/R/x86_64-pc-linux-gnu-library/3.4"

$RMARKDOWN_MATHJAX_PATH
[1] "/usr/lib/rstudio/resources/mathjax-26"

$R_PAPERSIZE
[1] "letter"

$R_PAPERSIZE_USER
[1] "letter"

$R_PDFVIEWER
[1] "/usr/bin/xdg-open"

$R_PLATFORM
[1] "x86_64-pc-linux-gnu"

$R_PRINTCMD
[1] "/usr/bin/lpr"

$R_RD4PDF
[1] "times,inconsolata,hyper"

$R_SESSION_TMPDIR
[1] "/tmp/RtmpYB9etw"

$R_SHARE_DIR
[1] "/usr/share/R/share"

$RS_LOCAL_PEER
[1] "/tmp/18469-rsession"

$RS_PPM_FD_READ
[1] "21"

$RS_PPM_FD_WRITE
[1] "22"

$RS_RPOSTBACK_PATH
[1] "/usr/lib/rstudio/bin/rpostback"

$RS_SHARED_SECRET
[1] "16816927778469308861804289383"

$RSTUDIO
[1] "1"

$RSTUDIO_CONSOLE_COLOR
[1] "256"

$RSTUDIO_CONSOLE_WIDTH
[1] "109"

$RSTUDIO_PANDOC
[1] "/usr/lib/rstudio/bin/pandoc"

$RSTUDIO_SESSION_PORT
[1] "18469"

$RSTUDIO_USER_IDENTITY
[1] "reilly"

$RSTUDIO_WINUTILS
[1] "bin/winutils"

$R_SYSTEM_ABI
[1] "linux,gcc,gxx,gfortran,?"

$R_TEXI2DVICMD
[1] "/usr/bin/texi2dvi"

$R_UNZIPCMD
[1] "/usr/bin/unzip"

$R_ZIPCMD
[1] "/usr/bin/zip"

$SED
[1] "/bin/sed"

$SESSION
[1] "ubuntu"

$SESSIONTYPE
[1] "gnome-session"

$SHELL
[1] "/bin/bash"

$SHLVL
[1] "0"

$SSH_AUTH_SOCK
[1] "/run/user/1000/keyring/ssh"

$TAR
[1] "/bin/tar"

$TERM
[1] "xterm-256color"

$UPSTART_EVENTS
[1] "xsession started"

$UPSTART_INSTANCE
[1] ""

$UPSTART_JOB
[1] "unity7"

$UPSTART_SESSION
[1] "unix:abstract=/com/ubuntu/upstart-session/1000/1585"

$USER
[1] "reilly"

$XAUTHORITY
[1] "/home/reilly/.Xauthority"

$XDG_CONFIG_DIRS
[1] "/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg"

$XDG_CURRENT_DESKTOP
[1] "Unity"

$XDG_DATA_DIRS
[1] "/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop"

$XDG_GREETER_DATA_DIR
[1] "/var/lib/lightdm-data/reilly"

$XDG_MENU_PREFIX
[1] "gnome-"

$XDG_RUNTIME_DIR
[1] "/run/user/1000"

$XDG_SEAT
[1] "seat0"

$XDG_SEAT_PATH
[1] "/org/freedesktop/DisplayManager/Seat0"

$XDG_SESSION_DESKTOP
[1] "ubuntu"

$XDG_SESSION_ID
[1] "c2"

$XDG_SESSION_PATH
[1] "/org/freedesktop/DisplayManager/Session0"

$XDG_SESSION_TYPE
[1] "x11"

$XDG_VTNR
[1] "7"

$XMODIFIERS
[1] "@im=ibus"

[1] ".GlobalEnv" "tools:rstudio" "package:stats" "package:graphics" "package:grDevices"
[6] "package:utils" "package:datasets" "package:methods" "Autoloads" "package:base" 
Log file: rdesktop.log
--------------------------------------------------

(Empty)

Log file: rsession-reilly.log
--------------------------------------------------

13 Oct 2017 21:15:06 [rsession-reilly] WARNING Process supervisor did not terminate within 1 second; LOGGED FROM: void {anonymous}::rCleanup(bool) /home/ubuntu/rstudio/src/cpp/session/SessionMain.cpp:1099

Here is the piece of code that is causing the error.

when this piece of code is saved into the document, upon opening and editing the file, rsession hangs. If this piece of code is not present, the document works fine. Not exactly sure what is going on. The piece of code is just an unfinished function I was working on but somehow it is blowing up Rstudio.

iteratively_impute_pca_zscore_remove_outliers <- function(matrix, ... ) {
  repeat {
    imputed.mat <- impute_less_than_x_NA(matrix)
    pc1_score_
    if (length(SamplesToRemove)==0)
  }
}
repeat {

} (length(samplesToRemove)==0){

}

Upvotes: 4

Views: 863

Answers (1)

Kevin Ushey
Kevin Ushey

Reputation: 21285

Oof! Thanks for reporting this and discussing the issue through in comments. The issue here is this bit of code:

repeat {

} (length(samplesToRemove)==0){

}

The problem is, to RStudio's diagnostic system, this looks like a function call (!), where repeat {} is the left-hand side of the function to be invoked. When RStudio attempts to evaluate this function, it gets stuck in the repeat {} loop, and never gets a chance to escape.

You should be able to work around this by moving this bit to a separate line:

repeat {

}

(length(samplesToRemove)==0){

}

But I'll file this for the RStudio folks and we'll try to get a fix.

Upvotes: 2

Related Questions