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
Valgrind issues on CRAN #16
Comments
The This is achieved by
=> rTRNG.valgrind-4.20-1.txt, showing very similar output to Digging this out, errors all refer to parsing a string representation of a TRNG engine, and actually occur when the string representation does not match what can be parsed (which we capture in yarn2$new("[yarn2 (1 2) (3 4)]") # OK, this is a valid representation
yarn2$new("[yarn2 (1 2) (3 4))") # This is an invalid representation, but no issues are detected
yarn2$new("[yarn2 (1 2) (3 4)") # This is an invalid representation, single issue detected
yarn2$new("!dummy!") # Invalid representation as in the unit tests, many issues detected The relevant code |
A possible solution has been considered and investigated, which changes trng/utility.hpp by comparing against the separator conditionally as follows: char c;
in.get(c);
// avoid comparison if there were parsing issues with other tokens or input is over
if (!in.fail() && !in.eof())
if (c != d.c)
in.setstate(std::ios::failbit); This was done manually in the rTRNG_4.20-1.tar.gz from CRAN => rTRNG_4.20-1-patch-valgrind.tar.gz and tested by replacing the rTRNG installation in the docker container above with
Assessed successfully on the miminal examples above, the full run via
shows no other errors => rTRNG_4.20-1-patch-valgrind.txt |
Status after updating to TRNG 4.23 (#18) checked on the corresponding branch as follows: R CMD build rTRNG
docker run --rm -ti -v $(pwd):/mydir wch1/r-debug
# inside the container:
RDvalgrind -e "install.packages(c('Rcpp', 'RcppParallel', 'testthat'))"
RDvalgrind -e "install.packages('/mydir/rTRNG_4.23-0.9000.tar.gz', INSTALL_opts = '--install-tests')"
RDvalgrind -d "valgrind --track-origins=yes" -e "library(testthat); library(rTRNG); testthat::test_package('rTRNG')" &> /mydir/rTRNG.valgrind-4.23-0.9000.txt => rTRNG.valgrind-4.23-0.9000.txt showing the same issue. |
…#16). * A patch component is added as 4.23.1, with an explicit mention about this being a version patched inside rTRNG in `TRNG.Version()`. * The process is made reproducible by extending inst/tools/upgradeTRNG.R to consume and apply a patch file.
A revised version of the patch mentioned above in #16 (comment) has been applied on top of the 4.23 updates introduced in #18 in a dedicated branch, see commit ed3dbc8 for details:
The patched 4.23.1 has been tested from the dedicated branch as follows: R CMD build rTRNG
docker run --rm -ti -v $(pwd):/mydir wch1/r-debug
# inside the container:
RDvalgrind -e "install.packages(c('Rcpp', 'RcppParallel', 'testthat'))"
RDvalgrind -e "install.packages('/mydir/rTRNG_4.23.1-0.9000.tar.gz', INSTALL_opts = '--install-tests')"
RDvalgrind -d "valgrind --track-origins=yes" -e "library(testthat); library(rTRNG); testthat::test_package('rTRNG')" &> /mydir/rTRNG.valgrind-4.23.1-0.9000.txt => rTRNG.valgrind-4.23.1-0.9000.txt shows no issue. |
Should be fixed in TRNG upstream via rabauke/trng4@22cc3b6. |
…h of v4.23 * Fixes #16 (valgrind issues). * This is based on a generated patch file for the fix in trng4, applied in inst/tools/upgradeTRNG.R.
Thanks a lot @rabauke! I have included the fix in rabauke/trng4@22cc3b6 as a patch back-ported to the latest TRNG release v4.23 we currently include in rTRNG as follows (for the sake of reproducibility and traceability): source("inst/tools/upgradeTRNG.R")
patch_file <- file.path(getwd(), "inst", "tools", "fix_uninitialized-memory_read_access-backport-v4.23.patch")
system(paste0("cd ~/GitHubProjects/trng4/ && git diff v4.23..22cc3b6 trng/utility.hpp > ", patch_file))
upgradeTRNG(version = "4.23", patch = patch_file) This was done with commit 032f559, see in particular fix_uninitialized-memory_read_access-backport-v4.23.patch Tested as rTRNG 4.23.1-0.9000 via: R CMD build rTRNG
docker run --rm -ti -v $(pwd):/mydir wch1/r-debug
# inside the container:
RDvalgrind -e "install.packages(c('Rcpp', 'RcppParallel', 'testthat'))"
RDvalgrind -e "install.packages('/mydir/rTRNG_4.23.1-0.9000.tar.gz', INSTALL_opts = '--install-tests')"
RDvalgrind -d "valgrind --track-origins=yes"
# inside the interactive R session
> library(rTRNG);
> yarn2$new("[yarn2 (1 2) (3 4)]") # OK, this is a valid representation
> yarn2$new("[yarn2 (1 2) (3 4))") # "failed to restore..." expected error, no valgrind issues
> yarn2$new("!dummy!") # "failed to restore..." expected error, no valgrind issues
> yarn2$new("[yarn2 (1 2) (3 4)") # "failed to restore..." expected error, no valgrind issues
> q("no")
# full valgrind test as on CRAN
RDvalgrind -d "valgrind --track-origins=yes" -e "library(testthat); library(rTRNG); testthat::test_package('rTRNG')" &> /mydir/rTRNG.valgrind-4.23.1-0.9000_fix_uninitialized-memory_read_access-backport-v4.23.txt => rTRNG.valgrind-4.23.1-0.9000_fix_uninitialized-memory_read_access-backport-v4.23.txt |
@rabauke, the test with your fix back-ported to rTRNG confirms the Given that rTRNG is meant to be based on a properly-controlled TRNG release upstream, we have a few options for submitting a new release of rTRNG by Jan 29:
We would be fine with any of the options above. |
@riccardoporreca See rabauke/trng4@610f783 and https://github.com/rabauke/trng4/tags Do not get confused by the fact that the version number in CMakeLists.txt jumps from 4.22 to 4.23.1. This is just due to the fact that the version number has not been adjusted for 4.23. |
Thank you so much for this @rabauke! I can then fully prepare for the rTRNG submission tomorrow based on the new patch release. |
…h of v4.23 * Fixes miraisolutions#16 (valgrind issues). * This is based on a generated patch file for the fix in trng4, applied in inst/tools/upgradeTRNG.R. # Conflicts: # inst/include/trng/utility.hpp # inst/tools/upgradeTRNG.R [valgrind-check]
* Based on the docker image `wch1/r-debug` and inspired by the CRAN checks logs for valgrind. * An artifact is produced containing the R CMD check output directory + a summary of the valgrind reported errors by file. * A failure is detected whenever a non-0 errors are found in any file. * The workflow is triggered on push and PRs on master, but can be triggered on any commit using [valgrind-check] in the comment. * The core bash script can be also executed locally, producing check results under `valgrind-check` (`.git`- and `.Rbuildignore`d).;
* Used to test backporting as a local patch of v4.23 the upstream TRNG fix rabauke/trng4@22cc3b6 addressing uninitialized memory issues reported by `valgrind` (#16), ahead of a proper patch release being available upstream. * The process is made reproducible by extending inst/tools/upgradeTRNG.R to consume and apply a patch file, adding a patch component to the version (e.g. 4.23.1), with an explicit mention in `TRNG.Version()` about this being a version patched inside rTRNG.
* Used to test backporting as a local patch of v4.23 the upstream TRNG fix rabauke/trng4@22cc3b6 addressing uninitialized memory issues reported by `valgrind` (#16), ahead of a proper patch release being available upstream. * The process is made reproducible by extending inst/tools/upgradeTRNG.R to consume and apply a patch file, adding a patch component to the version (e.g. 4.23.1), with an explicit mention in `TRNG.Version()` about this being a version patched inside rTRNG. [valgrind-check]
* Via inst/tools/upgradeTRNG.R * The patch release fixes the uninitialized-memory problems reported as `valgrind` issues in the CRAN package checks for rTRNG 4.20-1 (closes #16). [valgrind-check]
* Based on the docker image `wch1/r-debug` and inspired by the CRAN checks logs for valgrind. * An artifact is produced containing the R CMD check output directory + a summary of the valgrind reported errors by file. * A failure is detected whenever a non-0 errors are found in any file. * The workflow is triggered on push and PRs on master, but can be triggered on any commit using [valgrind-check] in the comment. * The core bash script can be also executed locally, producing check results under `valgrind-check` (`.git`- and `.Rbuildignore`d).;
* Used to test backporting as a local patch of v4.23 the upstream TRNG fix rabauke/trng4@22cc3b6 addressing uninitialized memory issues reported by `valgrind` (#16), ahead of a proper patch release being available upstream. * The process is made reproducible by extending inst/tools/upgradeTRNG.R to consume and apply a patch file, adding a patch component to the version (e.g. 4.23.1), with an explicit mention in `TRNG.Version()` about this being a version patched inside rTRNG. [valgrind-check]
* Via inst/tools/upgradeTRNG.R * The patch release fixes the uninitialized-memory problems reported as `valgrind` issues in the CRAN package checks for rTRNG 4.20-1 (closes #16). [valgrind-check]
CRAN checks for the released package version 4.20-1 reveals issues with
valgrind
, which should be investigated and fixed.Note that a new submission fixing the issue has been requested by the CRAN Team by 2021-01-29 in order to retain the package on CRAN
See comments below for the detailed investigation, which is summarized as follows:
valgrind
are all triggered by tests on errors when parsing an invalid string representation of a TRNG engine, which is pretty much a corner case we don't expect a typical user to hit.is pretty unlikely we canmight not be viable to get a new (patched) version of the upstream TRNG C++ library as a new release by Jan 29. As an alternative, we should patch the version we include as part of rTRNG.=> See Valgrind issues on CRAN #16 (comment) for an explicit and reproducible approach for including a small patch on rTRNG side.
=> See Valgrind issues on CRAN #16 (comment) and following comments regarding a proper fix in TRNG upstream.
Note:
=> see below Valgrind issues on CRAN #16 (comment)
See #21 for the consolidation of the upgrade to the patched upstream TRNG v4.23.1 into #20 on top of #18, including the introduction of
valgrind
checks via GitHub ActionsThe text was updated successfully, but these errors were encountered: