Skip to content

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

@jcheng5

Description

@jcheng5

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions