LightGBM: [R-package] R package crashes on windows when loaded together with {fansi} or anything that depends on it
This is probably related to:
- https://github.com/microsoft/LightGBM/issues/4045 and
- https://github.com/microsoft/LightGBM/issues/4007
Description
Using lightgbm while parsnip is loaded crashes the R session with: Exited with status -1073741819.
Reproducible example
Calling:
library(parsnip)
library(lightgbm)
data(agaricus.train, package='lightgbm')
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
model <- lgb.cv(
params = list(
objective = "regression",
metric = "l2"
) ,
data = dtrain
)
Environment info
I am using the dev version of LightGBM as suggested in https://github.com/microsoft/LightGBM/issues/4007#issuecomment-869080432 The error only occurs on Windows.
Here’s a GitHub actions run that shows the behavior. This shows that it works fine if parsnip is not loaded: https://github.com/curso-r/treesnip/runs/3037580458?check_suite_focus=true#step:9:1 And this one shows the error message: https://github.com/curso-r/treesnip/runs/3037580458?check_suite_focus=true#step:10:21
I could also reproduce it locally on a Windows machine, but I am not sure what’s the best way to get a stack trace. Let me know if I can help with further debugging.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 25
Commits related to this issue
- move Network method implementations from network.h to network.cpp (fixes #4464) — committed to microsoft/LightGBM by jameslamb 3 years ago
- move Network method implementations from network.h to network.cpp (fixes #4464) (#4496) — committed to microsoft/LightGBM by jameslamb 3 years ago
Now that #4496 has been merged, I believe this issue has been resolved.
Thanks so much to everyone involved here for your help with reproducible examples and debugging ideas!
I’m convinced that the root of the problem is related to the way that R loads DLLs, and that @dfsnow is right that
{lightgbm}and{fansi}are in conflict with each other somehow.If
{dplyr}is loaded before{lightgbm}but then thefansiDLL is unloaded before loading{lightgbm}, the reproducible example does not produce a segfault, and Dataset construction succeeds.If
{fansi}'s DLL is unloaded after loading{lightgbm}, that script produces a segfault atdtrain$construct().This finding plus the finding from https://github.com/microsoft/LightGBM/issues/4464#issuecomment-886244523 that commenting out
Network::num_machines()causes Dataset construction to succeed has led me to this working theory:I’m going to investigate this more closely with
dumpbinandlistdllsto see if I can identify the conflicts. I’m also going to try changing some details of{fansi}based on the advice in “Writing R Extensions”, especially https://cran.r-project.org/doc/manuals/R-exts.html#Controlling-visibility.Updates to follow!
I’m seeing the same issue. I’m guessing this may be related to #4007 and #4259. Some further details:
No crash
Running a clean install of the script below in a new project with renv enabled works for 3.2.1.99. See
sessionInfo()below.Session Info
Installing parsnip and loading it after lightgbm likewise does not result in a crash.
Session Info
Crash
However, loading parsnip before lightgbm results in a crash at the
lgb.cvstep.Session Info
Notes
renv::install("lightgbm", rebuild = TRUE)seems to fix this problem for both the CRAN and GitHub versions.Edit
Did a quick trip through the Imports of parsnip, loading each library before lightgbm 1-by-1. The following libraries cause crashes:
While the following cause no issues:
I then traveled through the dependencies of tibble and dplyr to find the lowest level library call that will cause a crash. Seems like fansi may be the actual culprit. The script below causes a crash for me in a fresh environment with lightgbm 3.2.1 (from CRAN) and 3.2.1.99 (from GitHub)
Session Info
I have multiple versions. 4.0.1 was first on PATH. And running Rscript --version gave this:
Didn’t know about it. Thanks for the help.
After solving a problem related to rtools everything works now 😃
This was installed for R-4.0.x even though I have R-4.1.x installed. Is this not supported for R 4.1.x?
Hi @jameslamb, thanks for looking at this!
I have added the
remove.packages("lightgbm")call and the error still persists: https://github.com/curso-r/treesnip/runs/3154997458?check_suite_focus=true#step:11:50 I thinkinstall.packagesultimately always removes the existing package folder before installing the package again.For the second question, I can confirm that error happens on both RStudio and on a vanilla R session: