Bug 16753 - wrapping an infinite recursive call in suppressWarnings() crashes R
Summary: wrapping an infinite recursive call in suppressWarnings() crashes R
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.2.3
Hardware: x86_64/x64/amd64 (64-bit) Linux
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-03-09 00:53 UTC by Hervé Pagès
Modified: 2016-03-12 17:29 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hervé Pagès 2016-03-09 00:53:06 UTC
> foo <- function() suppressWarnings(foo())
> foo()
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: segfault from C stack overflow
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
Segmentation fault (core dumped)

Of course nobody should do this but still, a crash is not nice...

See my sessionInfo() below.

H.

PS: I also tried this on Mac OS X with the same version of R (3.2.3) and
didn't get a crash.

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.4 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
Comment 1 Martin Maechler 2016-03-09 09:26:20 UTC
I agree that a crash is not nice..

I also don't get a crash on my (Fedora 22) Linux.

Even
    invisible(replicate(1000,  try( foo() ) ) )

just gives 1000 times the line

Error : evaluation nested too deeply: infinite recursion / options(expressions=)?

---
but then when I increase the 'expressions' option, "boom!" as for you :

> options(expressions=500000) # the maximum allowed
> foo()

Process R-devel exited abnormally with code 139 at Wed Mar  9 10:23:19 2016
Error: C stack usage  8285376 is too close to the limit
Error: C stack usage  8311700 is too close to the limit
Error: C stack usage  8338004 is too close to the limit
Error: C stack usage  8364308 is too close to the limit
Error: C stack usage  8390612 is too close to the limit
Error: C stack usage  8416916 is too close to the limit
Error: C stack usage  8443220 is too close to the limit
Error: C stack usage  8469524 is too close to the limit
Error: C stack usage  8495828 is too close to the limit
Error: C stack usage  8522132 is too close to the limit
Error: C stack usage  8548436 is too close to the limit
Error: C stack usage  8574740 is too close to the limit
Error: C stack usage  8601044 is too close to the limit
Error: C stack usage  8627348 is too close to the limit
Error: segfault from C stack overflow
Error: C stack usage  140723249637764 is too close to the limit
Error: C stack usage  140723249691124 is too close to the limit
Error: C stack usage  140723249744484 is too close to the limit
Error: C stack usage  140723249814644 is too close to the limit
Error: C stack usage  140723249884804 is too close to the limit
Error: C stack usage  140723249954964 is too close to the limit
Error: C stack usage  140723250025124 is too close to the limit

(that was with latest 'R-devel') ... so here I get a bit more "information".

If you increase  options(expression = .) on your Mac,
do you still not get a segfault?  (but what instead) ?
Comment 2 Luke Tierney 2016-03-09 13:20:01 UTC
This is a known issue with the way exit handers are run on stack unwinding. It is clear what has to be done, just need to find time to do it -- should happen fairly soon though.
Comment 3 Luke Tierney 2016-03-12 17:29:33 UTC
This is resolved by r70325. The error recovery code now unwinds the stack while running pending on.exit actions.