# Error: Status code 400 returned

#1

I first encountered this problem in September. RStudio will throw a ‘Status code 400 returned’ error every so often during any task, including writing code, saving files, executing code and startup. I have reinstalled RStudio (including removing .rstudio-desktop from home directory), upgraded R, worked in different projects and worked in those projects without loading any libraries, but the problem reemerges. Sometimes it can happen every 5 seconds, sometimes I can go as long as 120 seconds without seeing the error. Any idea what could be happening?

Here is a screenshot of what it looks like:
(I have more, but may not post multiple images.)

Diagnostics report:

[1] "1.1.383"

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

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

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

R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] secret_1.0.0      RPostgreSQL_0.6-2 DBI_0.7           ggmap_2.6.1
[5] jsonlite_1.5      forcats_0.2.0     stringr_1.2.0     dplyr_0.7.4
[13] ggplot2_2.2.1     tidyverse_1.2.1

loaded via a namespace (and not attached):
[1] reshape2_1.4.2    haven_1.1.0       lattice_0.20-35   colorspace_1.3-2
[5] htmltools_0.3.6   yaml_2.1.14       rlang_0.1.4       foreign_0.8-69
[13] bindrcpp_0.2      jpeg_0.1-8        bindr_0.1         plyr_1.8.4
[17] munsell_0.4.3     gtable_0.2.0      cellranger_1.1.0  rvest_0.3.2
[25] parallel_3.4.2    proto_1.0.0       broom_0.4.3       Rcpp_0.12.13
[29] geosphere_1.5-7   backports_1.1.1   openssl_0.9.9     scales_0.5.0
[33] mnormt_1.5-5      rjson_0.2.15      hms_0.3           png_0.1-7
[37] digest_0.6.12     stringi_1.1.6     rprojroot_1.2     grid_3.4.2
[41] cli_1.0.0         tools_3.4.2       maps_3.2.0        magrittr_1.5
[45] lazyeval_0.2.1    crayon_1.3.4      pkgconfig_2.0.1   xml2_1.1.1
[49] lubridate_1.7.1   assertthat_0.2.0  httr_1.3.1        rstudioapi_0.7
[53] R6_2.2.2          nlme_3.1-131      compiler_3.4.2

SysInfo:
sysname
"Darwin"
release
"17.0.0"
version
"Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64"
nodename
"MacBook-Pro.local"
machine
"x86_64"
"mennoschellekens"
user
"mennoschellekens"
effective_user
"mennoschellekens"

R Version:
_
platform       x86_64-apple-darwin15.6.0
arch           x86_64
os             darwin15.6.0
system         x86_64, darwin15.6.0
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
$__CF_USER_TEXT_ENCODING [1] "0x1F5:0x0:0x0"$Apple_PubSub_Socket_Render
[1] "/private/tmp/com.apple.launchd.FyeW2Fch9R/Render"

$CLICOLOR_FORCE [1] "1"$DISPLAY
[1] ":0"

$DYLD_FALLBACK_LIBRARY_PATH [1] "/Library/Frameworks/R.framework/Resources/lib:/Users/mennoschellekens/lib:/usr/local/lib:/usr/lib:::/lib:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/server"$EDITOR
[1] "vi"

$GIT_ASKPASS [1] "rpostback-askpass"$HOME
[1] "/Users/mennoschellekens"

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

$LN_S [1] "ln -s"$LOGNAME
[1] "mennoschellekens"

$MAKE [1] "make"$PAGER
[1] "/usr/bin/less"

$PATH [1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Postgres.app/Contents/Versions/latest/bin"$R_BROWSER
[1] "/usr/bin/open"

$R_BZIPCMD [1] "/usr/bin/bzip2"$R_DOC_DIR
[1] "/Library/Frameworks/R.framework/Resources/doc"

$R_GZIPCMD [1] "/usr/bin/gzip"$R_HOME
[1] "/Library/Frameworks/R.framework/Resources"

$R_INCLUDE_DIR [1] "/Library/Frameworks/R.framework/Resources/include"$R_LIBS_SITE
[1] ""

$R_LIBS_USER [1] "~/Library/R/3.4/library"$R_MAP_DATA_DIR
[1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/maps/mapdata/"

$R_MAP_DATA_DIR_WORLD [1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/maps/mapdata/"$R_PAPERSIZE
[1] "a4"

$R_PDFVIEWER [1] "/usr/bin/open"$R_PLATFORM
[1] "x86_64-apple-darwin15.6.0"

$R_PRINTCMD [1] "lpr"$R_QPDF
[1] "/Library/Frameworks/R.framework/Resources/bin/qpdf"

$R_RD4PDF [1] "times,inconsolata,hyper"$R_SESSION_TMPDIR
[1] "/var/folders/9p/t7zgftrn1l7c9671pz05r_t00000gn/T//Rtmp9EDU3x"

$R_SHARE_DIR [1] "/Library/Frameworks/R.framework/Resources/share"$R_SYSTEM_ABI
[1] "osx,gcc,gxx,gfortran,?"

$R_TEXI2DVICMD [1] "/usr/local/bin/texi2dvi"$R_UNZIPCMD
[1] "/usr/bin/unzip"

$R_ZIPCMD [1] "/usr/bin/zip"$RMARKDOWN_MATHJAX_PATH
[1] "/Applications/RStudio.app/Contents/Resources/resources/mathjax-26"

$RS_RPOSTBACK_PATH [1] "/Applications/RStudio.app/Contents/MacOS/rpostback"$RS_SHARED_SECRET
[1] "[redacted]"

$RSTUDIO [1] "1"$RSTUDIO_CONSOLE_COLOR
[1] "256"

$RSTUDIO_CONSOLE_WIDTH [1] "80"$RSTUDIO_PANDOC
[1] "/Applications/RStudio.app/Contents/MacOS/pandoc"

$RSTUDIO_SESSION_PORT [1] "47154"$RSTUDIO_USER_IDENTITY
[1] "mennoschellekens"

$RSTUDIO_WINUTILS [1] "bin/winutils"$SED
[1] "/usr/bin/sed"

$SHELL [1] "/bin/bash"$SSH_ASKPASS

$SSH_AUTH_SOCK [1] "/private/tmp/com.apple.launchd.T5d5cBSHjX/Listeners"$TAR
[1] "/usr/bin/tar"

$TERM [1] "xterm-256color"$TMPDIR
[1] "/var/folders/9p/t7zgftrn1l7c9671pz05r_t00000gn/T/"

$USER [1] "mennoschellekens"$XPC_FLAGS
[1] "0x0"

\$XPC_SERVICE_NAME
[1] "0"

[1] ".GlobalEnv"          "package:secret"      "package:RPostgreSQL"
[4] "package:DBI"         "package:ggmap"       "package:jsonlite"
[7] "package:forcats"     "package:stringr"     "package:dplyr"
[13] "package:tibble"      "package:ggplot2"     "package:tidyverse"
[16] "tools:rstudio"       "package:stats"       "package:graphics"
[19] "package:grDevices"   "package:utils"       "package:datasets"
Log file: rdesktop.log
--------------------------------------------------

(Empty)

Log file: rsession-mennoschellekens.log
--------------------------------------------------



RStudio v1.1 crashes - "Unable to establish connection with R session"
#2

@mhschel Before I’ve mentioned Shiny and Github as there was a similar error posted by someone due to that. However this doesn’t seem to be the case.

I do see that you have an awful amount of packages loaded, meaning that any of those could be causing your problem. I can somehow vouch for the tidyverse packages but the secret, forcats, RPostgreSQL, DBI and jsonlite could be among the reason why you see this.
I would try to detach them and see if they still bring problems.

With my problem before, the only way of solving and diagnosing it was by unloading every single package (except for the base ones), and then start loading them one by one until I would see a problem.

#3

@Felipe Even without loading any additional libraries, RStudio throws errors. I think the ‘package theory’ makes some sense (explains why the error showed up on different systems with different operating system that only shared code and libraries) but not sure where to go from here.

#4

But based on your previous error log, some packages are being attached automatically. When you look at the loaded packages, are they all off?

other attached packages: [1] secret_1.0.0 RPostgreSQL_0.6-2 DBI_0.7 ggmap_2.6.1 [5] jsonlite_1.5 forcats_0.2.0 stringr_1.2.0 dplyr_0.7.4 [9] purrr_0.2.4 readr_1.1.1 tidyr_0.7.2 tibble_1.3.4 [13] ggplot2_2.2.1 tidyverse_1.2.1

#5

Is this RStudio desktop, not Server? It’s presumably an HTTP status code (albeit not a very specific one), but that’s weird if you’re not making an HTTP request.

Edit:

The log does show some sort of requests failing:

20 Nov 2017 12:10:19 [rsession-mennoschellekens] CLIENT EXCEPTION (rsession-mennoschellekens): (TypeError) : undefined is not an object (evaluating 'this.a.a.r.row');|||org/rstudio/studio/client/workbench/views/source/editors/text/r/SignatureToolTipManager.java#134::execute|||com/google/gwt/core/client/impl/SchedulerImpl.java#167::runScheduledTasks|||com/google/gwt/core/client/impl/SchedulerImpl.java#338::flushPostEventPumpCommands|||com/google/gwt/core/client/impl/SchedulerImpl.java#76::execute|||com/google/gwt/core/client/impl/SchedulerImpl.java#140::execute|||com/google/gwt/core/client/impl/Impl.java#244::apply|||com/google/gwt/core/client/impl/Impl.java#283::entry0|||http://127.0.0.1:43039/#-1::anonymous|||com/google/gwt/cell/client/AbstractEditableCell.java#41::viewDataMap|||Client-ID: 33e600bb-c1b1-46bf-b562-ab5cba070b0e|||User-Agent: Mozilla/5.0 (Macintosh  Intel Mac OS X 10_13) AppleWebKit/604.1.38 (KHTML, like Gecko)
...


though I’m still not sure what they are.

#6

@alistaire That’s pretty common on R issues, mainly due to the way it communicates with RStudio. However, I’m stating this as a Layman as I’m not sure how R “talks” to RStudio. But I did see this before on unrelated issues for example one related to the data.table package which caused RStudio to crash.

#7

Can you also try taking a look at the request log, and checking out what the failed requests look like? You can do this by pressing Ctrl +  in the IDE. You should see a number of horizontal lines; each line represents the time between a request and a response sent from the RStudio desktop to the running R session. By clicking one of those lines, you should (hopefully) get a bit more information as to why you’re getting these 400 errors.

Unfortunately, it’s hard to say what could be causing this.

#8

@kevinushey Thanks you for the tip! I have taken screenshots of the results, which generally look similar.

#9

The results are always “undefined”.

#10

Thanks! This is expected for an active get_events request – since the event is still active (the client is waiting for an event from the server), there isn’t any response to send yet.

If I understand correctly, the error may be caused by the get_help RPC call being made. (Note that in the image you uploaded, one of the get_help` events has a very small bar colored in yellow – this is used for events for which the IDE did not understand the response.

If that’s the case, the error might be caused by an attempt to populate the help popup that accompanies autocompletion results. You might be able to trigger the 400 response by autocompleting a certain variable name in your R session; any idea what that might be?

In any event, if you could keep your eyes open for this error, and let us know if you encounter it and what you were attempting to autocomplete, that could be helpful.