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

[R-package] fix protection stack imbalance and unprotected objects (fixes #4390) #4391

Merged
merged 6 commits into from
Jun 27, 2021

Conversation

fabsig
Copy link
Contributor

@fabsig fabsig commented Jun 18, 2021

Fixes #4390.

@fabsig fabsig requested review from jameslamb and Laurae2 as code owners June 18, 2021 11:38
@jameslamb jameslamb added the fix label Jun 18, 2021
@jameslamb jameslamb changed the title [R-package] fix protection stack imbalance and unprotected objects is… [R-package] fix protection stack imbalance and unprotected objects (fixes #4390) Jun 18, 2021
Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

Thank you very much for your efforts and clear description of the problem in #4390!

I'll be able to give this a more thorough review later today or maybe tomorrow. For now, could you please address the minor linting issues described in https://github.com/microsoft/LightGBM/pull/4391/checks?check_run_id=2858695056?

You can see the following to understand how to replicate those locally:

pip install --user cpplint isort mypy

cpplint --filter=-build/c++11,-build/include_subdir,-build/header_guard,-whitespace/line_length --recursive ./src ./include ./R-package ./swig ./tests || exit -1

@jameslamb
Copy link
Collaborator

jameslamb commented Jun 18, 2021

/gha run r-valgrind

Workflow R valgrind tests has been triggered! 🚀
https://github.com/microsoft/LightGBM/actions/runs/950064363

Status: failure ❌.

Workflow R valgrind tests has been triggered! 🚀
https://github.com/microsoft/LightGBM/actions/runs/950064363

Status: failure ❌.

@jameslamb
Copy link
Collaborator

jameslamb commented Jun 18, 2021

/gha run r-solaris

Workflow Solaris CRAN check has been triggered! 🚀
https://github.com/microsoft/LightGBM/actions/runs/950065364

solaris-x86-patched: https://builder.r-hub.io/status/lightgbm_3.2.1.99.tar.gz-f462ced23b0e4dec8d603c104ce95c5f
solaris-x86-patched-ods: https://builder.r-hub.io/status/lightgbm_3.2.1.99.tar.gz-da0ec8c6c2804256bb1f04c0d8105bd9
Reports also have been sent to LightGBM public e-mail: http://www.yopmail.com/lightgbm_rhub_checks
Status: success ✔️.

@fabsig
Copy link
Contributor Author

fabsig commented Jun 18, 2021

Linting issues should be fixed.

@jameslamb
Copy link
Collaborator

Thanks! Sorry for the delays in CI runs...GitHub has a new mechanism (introduced to prevent abuse) which requires maintainers to manually approve CI runs for new contributors.

image

@fabsig
Copy link
Contributor Author

fabsig commented Jun 18, 2021

No hurry. A few comments on my changes that might be helpful for easier understanding:

  • I dropped all return statements in the catch statements in the R_API_END and CHECK_CALL macros to prevent potential protection stack imbalances. I don't see any use of these return statements.
  • I wrapped the R_API_BEGIN and R_API_END only around the calls to the C functions. It seems to me that the other operations don't need any error handling. In this way, the exception handling is encapsulated away from the protection
  • Added protection where needed

@jameslamb
Copy link
Collaborator

@fabsig we use a continuous integration job triggered by pull request comments which replicates CRAN's use of valgrind to check incoming packages.

I've tried to run it twice on this PR but the job is timing out.

https://github.com/microsoft/LightGBM/actions/runs/950064363

The job running on runner GitHub Actions 23 has exceeded the maximum execution time of 120 minutes.

It's possible that we were already very close to the 120-minute limit and that the changes here added enough time to hit that limit. Could you please update

timeout-minutes: 120
to 180 in this PR? Just so we can see how long it takes.

Really sorry for the inconvenience.

@fabsig fabsig requested a review from StrikerRUS as a code owner June 21, 2021 05:12
@fabsig
Copy link
Contributor Author

fabsig commented Jun 21, 2021

Could you please update

timeout-minutes: 120

Of course. Let me know if further changes are needed.

@jameslamb
Copy link
Collaborator

jameslamb commented Jun 22, 2021

/gha run r-valgrind

Workflow R valgrind tests has been triggered! 🚀
https://github.com/microsoft/LightGBM/actions/runs/959047226

Status: failure ❌.

Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

Thanks very much for this!

I ran the following to run rchk on this branch, and can confirm these changes eliminate the stack imbalance and protection errors found on master (#4390 (comment)) 🎉

git clone --recursive git@github.com:fabsig/LightGBM.git fabsig-LightGBM
cd fabsig-LightGBM
git fetch origin R_package_protection
git checkout R_package_protection

sh build-cran-package.sh
mkdir packages
cp lightgbm_3.2.1.99.tar.gz packages
docker run -v `pwd`/packages:/rchk/packages kalibera/rchk:latest /rchk/packages/lightgbm_3.2.1.99.tar.gz

end of rchk logs on this branch

Installed libraries of package  lightgbm 
[1] "/rchk/packages/libsonly/lightgbm/libs/lightgbm.so"

Library name (usually package name): lightgbm
Initialization function: R_init_lightgbm
Functions: 41
Checked call to R_registerRoutines: 1
ERROR: too many states (abstraction error?) in function strptime_internal
Analyzed 39640 functions, traversed 107321 states.

Rchk version: 3d653b7c8f92dac912532856b55f44d2986c6553
R version: 79889/R Under development (unstable) (2021-01-27 r79889)
LLVM version: 10.0.0

So overall, this looks great! Please just see a few minor comments I left about formatting.


I think that our friends over at {xgboost} (@trivialfis @hcho3) would also really appreciate a similar contribution, if you have time. That project has similar uses of inline CHAR(asChar()) without protection. For example:

https://github.com/dmlc/xgboost/blob/da1ad798cabb6868be368bd262814cebcbf3d094/R-package/src/xgboost_R.cc#L416-L421

Would you consider opening an issue similar to #4390 in https://github.com/dmlc/xgboost/issues? Not strictly required here, but we have borrowed a lot from that project and try to give back to it when possible.

R-package/src/lightgbm_R.cpp Outdated Show resolved Hide resolved
R-package/src/lightgbm_R.cpp Show resolved Hide resolved
@fabsig
Copy link
Contributor Author

fabsig commented Jun 23, 2021

I think that our friends over at {xgboost} (@trivialfis @hcho3) would also really appreciate a similar contribution, if you have time. That project has similar uses of inline CHAR(asChar()) without protection. For example:

https://github.com/dmlc/xgboost/blob/da1ad798cabb6868be368bd262814cebcbf3d094/R-package/src/xgboost_R.cc#L416-L421

Would you consider opening an issue similar to #4390 in https://github.com/dmlc/xgboost/issues? Not strictly required here, but we have borrowed a lot from that project and try to give back to it when possible.

Thanks for the suggestion. I will do that.

@trivialfis
Copy link

Thanks for letting us know!

Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

These changes look great! Thanks for a narrowly-scoped and very clearly-explained pull request that was easy to review.

I am leaving a "request changes" review only to block merging for now. I want to wait to merge this until we can run valgrind checks on this branch, which won't be possible until #4404 is merged.

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Jun 26, 2021

/gha run r-valgrind

Workflow R valgrind tests has been triggered! 🚀
https://github.com/microsoft/LightGBM/actions/runs/974132065

Status: success ✔️.

@jameslamb jameslamb self-requested a review June 27, 2021 05:01
Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

valgrind seems happy with these changes (#4391 (comment)).

I also re-ran rchk on this branch and it did not detect any remaining issues.

Installed libraries of package  lightgbm
[1] "/rchk/packages/libsonly/lightgbm/libs/lightgbm.so"
/rchk/scripts/check_package.sh: line 100:   561 Killed                  $RCHK/src/$T $RBC $F > $FOUT 2>&1

Library name (usually package name): lightgbm
Initialization function: R_init_lightgbm
Functions: 41
Checked call to R_registerRoutines: 1

Rchk version: 3d653b7c8f92dac912532856b55f44d2986c6553
R version: 79889/R Under development (unstable) (2021-01-27 r79889)
LLVM version: 10.0.0

Thanks very much for this contribution 🙌

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[R-package] Protection stack imbalance and unprotected objects
4 participants