Bug 14332 - Infinite loop in Rstd_CleanUp
Infinite loop in Rstd_CleanUp
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Low-level
R 2.11.1 patched
All All
: P5 minor
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-07-09 22:17 UTC by David Hinds
Modified: 2010-07-12 19:31 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Hinds 2010-07-09 22:17:05 UTC
In src/unix/sys-std.c, Rstd_CleanUp() does not check the return status of R_ReadConsole().  In admittedly unusual circumstances where the console has gone away, this can result in an infinite loop.

I ran into this bug when using a shared library not under my control that changed the default signal handler for SIGHUP.  So in some sense one could argue that all bets are off.  In any case, the effect is that if the terminal goes away (say I close the shell window R is running in), the SIGHUP doesn't kill R directly.  Instead, R's main event loop gets an error or EOF, and starts shutting things down.  Rstd_CleanUp() calls R_ReadConsole() to give the "Save workspace image? [y/n/c]" prompt, but this returns 0 (an error).  This isn't caught, so RstdCleanUp() loops back and tries again... and again... and again.

Without any other libraries, an easy way to see the issue is run R interactively and then send an EOF at the R prompt.  The "Save..." prompt will pop up, and another EOF will just bring up the prompt again.  I think it could be argued that R should not continue trying to read from the terminal after it sees an EOF?

A simple fix is to check the return status and treat an error as an 'N' response.

A work-around is to run R with --save (or --no-save) so that the question is not asked.
Comment 1 Brian Ripley 2010-07-12 19:31:20 UTC
It could indeed be argued about.
But behaviour changed for 2.12.0

Note: this is NOT all platforms: Windows (and GUI-based platforms)
behave differently.