Skip to content

R crashes when attempting rlang (devel) tests #654

Closed

Description

@egnha

Is the following crash reproducible?

As of the current commit, running tests of current dev version of rlang

devtools::test()

gives

Loading rlang
unloadNamespace("rlang") not successful, probably because another loaded package depends on it.Forcing unload. If you encounter problems, please restart R.
Loading required package: testthat
Testing rlang
✔ | OK F W S | Context
⠏ |  0       | arg
 *** caught bus error ***
address 0x7f9e2901b778, cause 'non-existent physical address'

Traceback:
 1: is_null(.ns)
 2: lang(captureArg, substitute(arg))
 3: enquo(object)
 4: force(quo)
 5: quasi_label(enquo(object), label)
 6: expect_identical(arg_match(myarg, c("bar", "foo")), "foo")
 7: eval(code, test_env)
 8: eval(code, test_env)
 9: withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test))         skip_empty()}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error)
10: doTryCatch(return(expr), name, parentenv, handler)
11: tryCatchOne(expr, names, parentenv, handlers[[1L]])
12: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
13: doTryCatch(return(expr), name, parentenv, handler)
14: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]),     names[nh], parentenv, handlers[[nh]])
15: tryCatchList(expr, classes, parentenv, handlers)
16: tryCatch(withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test))         skip_empty()}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error), error = handle_fatal,     skip = function(e) {    })
17: test_code(desc, code, env = parent.frame())
18: test_that("matches arg", {    myarg <- c("foo", "baz")    expect_identical(arg_match(myarg, c("bar", "foo")), "foo")    expect_error(regex = "`myarg` should be one of: \"bar\" or \"baz\"",         arg_match(myarg, c("bar", "baz")))})
19: eval(code, test_env)
20: eval(code, test_env)
21: withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test))         skip_empty()}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error)
22: doTryCatch(return(expr), name, parentenv, handler)
23: tryCatchOne(expr, names, parentenv, handlers[[1L]])
24: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
25: doTryCatch(return(expr), name, parentenv, handler)
26: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]),     names[nh], parentenv, handlers[[nh]])
27: tryCatchList(expr, classes, parentenv, handlers)
28: tryCatch(withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test))         skip_empty()}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error), error = handle_fatal,     skip = function(e) {    })
29: test_code(NULL, exprs, env)
30: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
31: force(code)
32: with_reporter(reporter = reporter, start_end_reporter = start_end_reporter,     {        lister$start_file(basename(path))        source_file(path, new.env(parent = env), chdir = TRUE,             wrap = wrap)        end_context()    })
33: FUN(X[[i]], ...)
34: lapply(paths, test_file, env = env, reporter = current_reporter,     start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
35: force(code)
36: with_reporter(reporter = current_reporter, results <- lapply(paths,     test_file, env = env, reporter = current_reporter, start_end_reporter = FALSE,     load_helpers = FALSE, wrap = wrap))
37: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure,     stop_on_warning = stop_on_warning, wrap = wrap)
38: (function (path, filter = NULL, reporter = default_reporter(),     env = test_env(), ..., encoding = "unknown", load_helpers = TRUE,     stop_on_failure = FALSE, stop_on_warning = FALSE, wrap = TRUE) {    if (!missing(encoding) && !identical(encoding, "UTF-8")) {        warning("`encoding` is deprecated; all files now assumed to be UTF-8",             call. = FALSE)    }    if (load_helpers) {        source_test_helpers(path, env)    }    source_test_setup(path, env)    on.exit(source_test_teardown(path, env), add = TRUE)    withr::local_envvar(list(R_TESTS = "", TESTTHAT = "true"))    withr::local_options(list(oldie_verbose_retirement = TRUE))    paths <- find_test_scripts(path, filter, ...)    test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure,         stop_on_warning = stop_on_warning, wrap = wrap)})("/Users/eha/projects/rlang/tests/testthat", filter = NULL,     env = <environment>, load_helpers = FALSE, encoding = "unknown")
39: do.call(testthat::test_dir, testthat_args)
40: force(code)
41: withr::with_envvar(r_env_vars(), do.call(testthat::test_dir,     testthat_args))
42: devtools::test()
An irrecoverable exception occurred. R is aborting now ...
Bus error: 10

Session info:

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

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.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

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

Activity

  1. egnha commented on Oct 19, 2017

    @egnha
    Author

    No crash with CRAN version of testthat.

  2. hadley commented on Oct 20, 2017

    @hadley
    Member

    @lionel- can you please take a look?

  3. lionel- commented on Oct 20, 2017

    @lionel-
    Member

    I see failures but I don't see a crash. Maybe you need to recompile and reinstall testthat?

  4. egnha commented on Oct 21, 2017

    @egnha
    Author

    @lionel- I still get a crash with the following procedure:

    1. Remove both testthat and rlang
    2. Install testthat with devtools::install_github()
    3. Install rlang with devtools::install_github()
    4. Test latest commit of rlang with devtools::test()

    However, no crash if I skip 3 and proceed to 4. (I presume this might be what you observed.)

  5. lionel- commented on Oct 22, 2017

    @lionel-
    Member

    This is because the imports environment of testthat is not updated when rlang is reloaded by devtools:

    x <- rlang::is_null
    y <- ns_imports_env("testthat")$is_null
    
    y
    #> function(x) {
    #>   .Call(rlang_is_null, x)
    #> }
    #> <environment: namespace:rlang>
    
    pryr::address(x)
    #> [1] "0x7ffb5d036f80"
    
    pryr::address(y)
    #> [1] "0x7ffb5d174fc0"

    It might be fine if these closures were scoped in the same namespace but that is not the case:

    env_get(x, "rlang_is_null")
    #> ...
    #>
    #> $address
    #> <pointer: 0x7ffb58e2bd00>
    #> attr(,"class")
    #> [1] "RegisteredNativeSymbol"
    #>
    #> ...
    
    env_get(y, "rlang_is_null")
    #> ...
    #>
    #> $address
    #> <pointer: 0x7ffb5b8704f0>
    #> attr(,"class")
    #> [1] "RegisteredNativeSymbol"
    #>
    #> ...

    Thus the .Call()s from the old rlang closures in testthat's imports are calling into dangling pointers.

    @jimhester Could something be done about this in pkgload? In ESS we update the imports env of all loaded packages when the user updates a function definition in some namespace.

  6. hadley commented on Nov 2, 2017

    @hadley
    Member

    Moved to pkgload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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