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

Interruption of callbacks can result in c++ exception (unknown reason) message #55

Open
jcheng5 opened this issue May 2, 2018 · 8 comments

Comments

@jcheng5
Copy link
Member

jcheng5 commented May 2, 2018

Downstream issues:
rstudio/shiny#1967 (comment)
rstudio/httpuv#130


This happens only under certain circumstances, when a native/Rcpp callback function is registered with the native later::later API, and an interrupt occurs within the callback.

Rcpp::cppFunction(depends = "later",
  code = '
  void test() {
    later::later(doIt, 0, 0);
  }
  ',
  includes = '
  #include <later_api.h>

  void doIt(void* data) {
    throw new Rcpp::internal::InterruptedException();
  }
  ')

Run test() to reproduce; you should see later: c++ exception (unknown reason) occurred while executing callback.

In the example above, we are calling throw Rcpp::internal::InterruptedException() explicitly, but it can happen through user gesture as well:

Rcpp::cppFunction(depends = "later",
  code = '
  void test2() {
    later::later(doIt, 0, 0);
  }
  ',
  includes = '
  #include <later_api.h>

  void doIt(void* data) {
    Rcpp::Function func("Sys.sleep");
    func(5);
  }
  ')

Run test2(); later::run_now(5), and quickly hit Esc or Ctrl+C to interrupt. You should see Error in execCallbacks(timeoutSecs) : c++ exception (unknown reason).

The root cause seems to have to do with the compilation unit of the throw Rcpp::internal::InterruptedException versus that of the catch (Rcpp::internal::InterruptedException) (usually the latter is via the END_RCPP macro). A minimal repro for this problem is at https://github.com/jcheng5/exceptiontest.

@jcheng5
Copy link
Member Author

jcheng5 commented May 2, 2018

Hmmm. exceptiontest doesn't repro on Ubuntu using gcc. But the first example in this issue does repro. But not the second example.

@wch
Copy link
Member

wch commented May 3, 2018

Is it possible that the difference you're seeing between Linux and Mac is because on Linux, all packages are compiled from source on the test machine, but on Mac, some packages (like Rcpp) were built on a different machine with possibly a different compiler and compiler settings?

@jcheng5
Copy link
Member Author

jcheng5 commented May 3, 2018

Possibly. Could also be clang vs g++ in general?

@JackStat
Copy link

We am also having issues running our plumber service in docker. We keep having containers implode on us with this stack trace

*** caught segfault ***
address (nil), cause 'unknown'

1: .Call("_later_execCallbacks", PACKAGE = "later", timeoutSecs)
2: execCallbacks(timeoutSecs)
3: run_now(check_time)
4: service(0)
5: httpuv::runServer(host, port, self)
6: pr$run(host = "0.0.0.0", port = 8000, swagger = TRUE)

An irrecoverable exception occurred. R is aborting now ...

Is this the same issue? Sorry I am kind of at a loss on this one

@wch
Copy link
Member

wch commented May 31, 2018

@JackStat Are you able to provide us with a reproducible example -- say, a Dockerfile that builds an image that will raise that same error?

Also, the segfault you're seeing is probably a separate problem. Can you file a new issue for this?

@JackStat
Copy link

It's so buried in our proprietary code I don't know if I can but I will try. We installed httpuv 1.3.5 and the issue went away. I will continue to dig and hopefully put this in the appropriate place

@wch
Copy link
Member

wch commented May 31, 2018

Thanks, that would be very helpful. I think that it would make sense to file an issue in the httpuv repo.

@boennecd
Copy link

This may be completely unrelated in which case I am sorry, but I have seen some issues with re-throwing exceptions but only on clang-11 using libc++. It is not with your library but the error is due to an exception, it can yield c++ exception (unknown reason) and a segfault like in JackStat's example. The example is provided here.

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

4 participants