Bug 15914 - R crashes when running nlminb() many times, windows only
Summary: R crashes when running nlminb() many times, windows only
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Windows GUI / Window specific (show other bugs)
Version: R 3.1.0
Hardware: x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 normal
Assignee: R-core
URL:
: 15244 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-07-29 14:56 UTC by Yves Rosseel
Modified: 2014-07-30 16:27 UTC (History)
2 users (show)

See Also:


Attachments
R script to reproduce crash under windows (1.41 KB, text/plain)
2014-07-29 14:56 UTC, Yves Rosseel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yves Rosseel 2014-07-29 14:56:14 UTC
Created attachment 1634 [details]
R script to reproduce crash under windows

The script in attach calls nlminb() from the stats package many, many times (say, > 1 million times). After a large, but varying number of times, the script crashes. This is both using the RGui.exe, or running the script using Rscript.exe in a dos command box.

This script is based on a function that computes the tetrachoric correlation from a 2x2 frequency table, but I changed it to avoid the use of an external package (pbivnorm). It now estimates (using ML) the cell proportion in the (1,1) cell, given the marginal proportions. Just to have a reproducible example that runs rather fast. The full script (10 million runs) takes about 4-5 hours on a modest laptop, but usually crashes before it reaches the end with the message 'R for windows front-end has stopped working'.

Some further observations:
- this is only under windows; no crashes under linux and/or Mac OSX
- 32 vs 64bit does not seem to matter
- the crashes do NOT occur if the nlminb() function is replaced by the optim() function (using method="BFGS" or method "L-BFGS-B")
- the crashes occur with all previous versions of R down to and including R 2.14.2. Interestingly, the crashes do NOT occur in R 2.14.1 (or earlier.) However, neither the underlying c-code nor the R code for nlminb() have changed between 2.14.1 and 2.14.2.

This is the output of sessionInfo():

R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

I am no expert in debugging under windows, but I installed Dr Mingw, and this is the crash report:

Rscript.exe caused an Access Violation at location 0000000071123FB4 in module stats.dll Reading from location 0000000014160000.

AddrPC   Params
71123FB4 00000000 00000000 00000000 stats.dll!R_init_stats
7112460A 003984A0 0440CDF0 0440CDD0 stats.dll!R_init_stats
6C816368 136D7720 136C1DB8 00120788 R.dll!Runzip
6C77276C 05C40F90 6C82DF6A 00000000 R.dll!do_Rprof
6C77D486 136D8968 13C64910 05C41118 R.dll!Rf_eval
6C780582 05C41118 136D84D0 001205C8 R.dll!Rf_applyClosure
6C77D514 00000030 003984A0 001240E0 R.dll!Rf_eval
6C77EF9A 00000004 00050000 3FC999999999999A R.dll!Rf_eval
6C77D725 00000001 00000000 05C431B8 R.dll!Rf_eval
6C77F160 00000B12 00123F20 00000002 R.dll!Rf_eval
6C77D725 003984A0 137DEF48 137DF108 R.dll!Rf_eval
6C780DA6 05C43298 00122010 05C432D0 R.dll!Rf_applyClosure
6C77D725 001365FB 7FEFFC14A17 12970018 R.dll!Rf_eval
6C74C8AB 125DA038 125DA038 125DA038 R.dll!Rf_ReplIteration
6C74CB52 00000001 00297F90 00000005 R.dll!Rf_ReplIteration
6C74DA0B 00000005 00135D40 00135D2A R.dll!run_Rmainloop
0040168F 00000002 00135D00 00000000 Rscript.exe!0x168f
004034C3 00000001 00135D00 00000000 Rscript.exe!0x34c3
004013CE 00000000 00000000 00000000 Rscript.exe!0x13ce
004014E8 00000000 00000000 00000000 Rscript.exe!0x14e8
779CF34D 00000000 00000000 00000000 kernel32.dll!BaseThreadInitThunk
77B02CA1 00000000 00000000 00000000 ntdll.dll!RtlUserThreadStart
Comment 1 Duncan Murdoch 2014-07-29 15:02:26 UTC
This may be the same bug as PR#15244, <https://bugs.r-project.org/bugzilla/show_bug.cgi?id=15244>.
Comment 2 Duncan Murdoch 2014-07-29 21:54:35 UTC
This looks like a gcc 4.6.3 bug:  it was executing some code that was not supposed to execute.

I think I have put in a workaround for this now.  Could you please try R-devel in a build of at least r66272?  If you can't trigger it there, I'll backport it to R-patched.
Comment 3 Yves Rosseel 2014-07-30 15:28:25 UTC
Yes, this seems to have done the trick. I tried r66272, and I could run the full script twice without a single crash.
Comment 4 Duncan Murdoch 2014-07-30 16:26:36 UTC
Appears to be a gcc compiler optimization bug; fixed by removing some unused code.
Comment 5 Duncan Murdoch 2014-07-30 16:27:17 UTC
*** Bug 15244 has been marked as a duplicate of this bug. ***