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

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Jun 22 08:57:26 EDT 2009

On Jun 22, Matthew Flatt wrote:
> 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.

Would it be possible to somehow detect that the error is a write error
on the closed `current-output-port' at a lower level and have a
parameter that determines what to do in this case?  Such a parameter
can be set while the repl prints the prompt, and also wrapped around
things like:

  mz -e '(parameterize ([exit-on-closed-output #t])
           (for ([i (in-naturals)]) (printf "~s\n" i)))' | head -5

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.