Infinite error loop if output is redirected to a network stream and the network connection is closed
Maxima, a computer algebra system written in lisp, talks to its front-end over a network-connection that is setup the following way:
(defun setup-client (port &optional (host "localhost"))
(multiple-value-bind (sock condition) (ignore-errors (open-socket host port))
(unless sock
; It appears that we were unable to open a socket or connect to the
; specified port.
(mtell (intl:gettext "~%Unable to connect Maxima to port ~:M.~%") port)
(mtell (intl:gettext "Error: ~A~%") condition)
($quit))
#+ecl (setq *old-stdin* *standard-input*
*old-stdout* *standard-output*
*old-sterr* *error-output*
*old-term-io* *terminal-io*
*old-debug-io* *debug-io*)
(setq *standard-input* sock)
(setq *standard-output* sock)
(setq *error-output* sock)
(setq *terminal-io* sock)
(setq *trace-output* sock)
(format t "pid=~a~%" (getpid))
(force-output sock)
(setq *debug-io* sock))
(values))
If the network connection drops this produces an error message from ECL's side that (as the network connection is down) produces an error message from ECL's side that... in the end causes an endless loop that uses up 100% of on CPU.
The operating system is Ubuntu (Artful pre-alpha, but the problem was there with older Ubuntu versions, as well).
(lisp-implementation-version)
"16.1.2"
(ext:lisp-implementation-vcs-id)`
"UNKNOWN"
> (software-type)
(SOFTWARE-TYPE)
> (software-version)
"4.13.1-041301-generic"
> (machine-type)
"x86_64"
> *features*
(:WALKER :LINUX :FORMATTER :ECL-WEAK-HASH :LITTLE-ENDIAN :ECL-READ-WRITE-LOCK
:LONG-LONG :UINT64-T :UINT32-T :UINT16-T :RELATIVE-PACKAGE-NAMES :LONG-FLOAT
:UNICODE :DFFI :CLOS-STREAMS :CMU-FORMAT :UNIX :ECL-PDE :DLOPEN :CLOS :THREADS
:BOEHM-GC :ANSI-CL :COMMON-LISP :IEEE-FLOATING-POINT :PREFIXED-API :FFI
:X86_64 :COMMON :ECL)
Normally most front-ends try to quit maxima in a friendly way before they drop the network connection. But if the front-end crashes (and therefore the connection to stdin, stdout and stderr drops) clisp and sbcl quit while ecl will keep one CPU busy.