[plt-scheme] mzscheme enters infinite loop when unable to write to stdout

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jun 22 08:12:51 EDT 2009

At Sun, 21 Jun 2009 12:08:05 +0100, "Paulo J. Matos" wrote:
> On Sat, 2009-06-20 at 20:38 -0400, Andrew Wilcox wrote:
> > mzscheme enters an infinite loop printing "error writing to stream
> > port" at the REPL if it is unable to write to stdout.  (the odd
> > position of the ">" prompt in the output is due to redirecting stdout
> > to a pipe).
> > 
> 
> I confirm this issue also in latest 4.2.

I'm not sure there's a good solution to this. (This is an old issue.)

The problem is that the exception is coming from deep inside `write'. A
REPL generally shouldn't not exit just because printing a result
failed. It might be that something went wrong calling a custom write
handler, or maybe there was a transient error on the output port, and
so the programmer might want to try again.

In this case, there are no custom write handlers involved, because the
failure happens while printing a prompt (I think). It might make sense
to have the REPL abort if printing a prompt somehow fails... but,
again, the prompt-printing part of a REPL is controlled through the
`current-prompt-read' parameter, and not all errors during the
prompt-read handler should abort the REPL.

I see that some other Scheme systems (Chicken and Larceny) exit when
there's a broken-pipe error for an output attempt (REPL or anything
else). I think it's better to raise an exception. Ikarus raises an
exception, but it exits from the REPL; my guess is that Ikarus catches
only read and eval exceptions in its REPL. In any case, you can get
into the same infinite-loop trouble with Ikarus by truncating stderr
(i.e., attempting to print an error messages leads to an exception,
etc.).

Any ideas?



Posted on the users mailing list.