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

Add check for the LibR.so that rsession believes it's using #9893

Merged
merged 4 commits into from Sep 30, 2021

Conversation

cm421
Copy link
Contributor

@cm421 cm421 commented Sep 27, 2021

Intent

Addresses https://github.com/rstudio/rstudio-pro/issues/2477 by adding a check on the libR.so that rsession believes it is running. If there are issues with loading that shared object, generate an error.

Note that this does not fix the problem. Instead it creates an error that can be used to find and fix the cause of the problem, which is a system environment issue

Approach

The linked issue describes the problem in detail, but essentially while linux is loading the rsession binary, if there's an issue with libR.so, it may load a different libR.so without rsession's knowledge. To address this, we check for issues manually once rsession is fully loaded by calling dload() with RTLD_NOLOAD. Any issues Linux had with loading the shared object will become apparent with that call, and the error can then be forwarded on to an error.

This is linux-only code; Windows and MacOS won't perform this check.

Automated Tests

There are no unit tests included. Integration tests will require:

  • A linux environment with at least 2 R installations
    • One system R install
    • One custom R install
  • Ability to "disable" the custom R version's libR.so before the test by chmoding out permissions so it can't be opened, and then restoring the permissions after the test is done

The test should include

  • Start an rsession with the default system R install
    • No error should be generated
  • Switch R version to the broken custom version
    • Error should be generated

QA Notes

None, see testing section above for how to reproduce/test

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

@cm421 cm421 marked this pull request as ready for review September 28, 2021 17:34
Copy link
Collaborator

@MariaSemple MariaSemple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant solution! Very excited to see this improve for users.

* Verify that we can load a library (without actually loading it)
* by passing RTLD_NOLOAD to dlopen
*/
Error verifyLibrary(const std::string& libPath, void** ppLib)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you never use ppLib, I don't think you should call it here. You're also never closing the handle on success, but I'm not sure if that matters.

-1,
"Attempt to verify library failed",
ErrorLocation());
error.addProperty("lib-path", libPath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error.addProperty("lib-path", libPath);
error.addProperty("path", libPath);

Comment on lines 707 to 712
if (!ensureLibRSoValid())
LOG_ERROR_MESSAGE(s_libRSoWarning +
". Linux may have loaded a different libR.so than requested."
" R_HOME: " + rsession::module_context::rHomeDir() +
", R Version: " + rsession::module_context::rVersion());

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than use a static which isn't thread safe, we should log this error message from within the ensureLibRSoValid() method.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, should we exit here? Or at the very list emit a similar error to the R Console so that the user can be informed? IIRC, this error message will only go to our log files, and a big problem with this behaviour is that the user is unware that they're using the wrong version of R. We should probably include a note about contacting your system administrator if the versions don't match.

Add warning to user's console
Update warning text
Clean up verifyLibrary() prototype
Copy link
Collaborator

@MariaSemple MariaSemple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cm421 cm421 merged commit ff301e8 into main Sep 30, 2021
@valerie-rstudio valerie-rstudio deleted the bugfix/check-custom-r-version branch January 21, 2022 17:54
@abalter
Copy link

abalter commented Oct 10, 2023

This is really not fixed. I'm still having the same problem. I've tried setting the path to R and R libraries in all of the places the docs say. For instance, /etc/rstudio/rsession-profile and /etc/rstudio/rserver.conf. I've made sure that root is using the same R as I am.

error while loading shared libraries: libR.so - R Admins - Posit Community
https://community.rstudio.com/t/error-while-loading-shared-libraries-libr-so/101389/13

r - RStudio Server (community) can't find libR.so even though it is in path - Stack Overflow
https://stackoverflow.com/questions/74299104/rstudio-server-community-cant-find-libr-so-even-though-it-is-in-path

/usr/local/lib64/R/lib/libR.so: cannot open shared object file: No such file or directory - Stack Overflow
https://stackoverflow.com/questions/69013147/usr-local-lib64-r-lib-libr-so-cannot-open-shared-object-file-no-such-file-or

r - Error with shared library with RStudio Server - Stack Overflow
https://stackoverflow.com/questions/33897998/error-with-shared-library-with-rstudio-server

r - error while loading shared libraries: libR.so - Stack Overflow
https://stackoverflow.com/questions/37967497/error-while-loading-shared-libraries-libr-so

error while loading shared libraries: libR.so: cannot open shared object file
https://groups.google.com/g/epacts/c/5JNFkpmyuSU

ubuntu - libR.so not found in R Rstudio - Stack Overflow
https://stackoverflow.com/questions/60893387/libr-so-not-found-in-r-rstudio

R shared library (/usr/local/lib/R/lib/libR.so) not found. If this is a custom build of R, was it built with the --enable-R-shlib option? - RStudio IDE - Posit Community
https://community.rstudio.com/t/r-shared-library-usr-local-lib-r-lib-libr-so-not-found-if-this-is-a-custom-build-of-r-was-it-built-with-the-enable-r-shlib-option/126418

Rstudio error "R shared library (/usr/local/lib/R/lib/libR.so) not found." - RStudio IDE - Posit Community
https://community.rstudio.com/t/rstudio-error-r-shared-library-usr-local-lib-r-lib-libr-so-not-found/62598

[R] R shared library (/usr/lib64/R/lib/libR.so) not found.
https://stat.ethz.ch/pipermail/r-help/2018-August/455984.html

RStudio Server (community) can't find libR.so even though it is in path. · Issue #12281 · rstudio/rstudio
#12281

@abalter
Copy link

abalter commented Oct 10, 2023

How about just adding a switch to rstudio-server? Then I could run sudo rstudio-server start --r_path=/home/balter/micromamba/bin/R r_libs=/home/balter/micromamba/lib/R/lib

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

Successfully merging this pull request may close these issues.

None yet

3 participants