fd-closing finalizer on streams considered unwarranted

Bug #630680 reported by Tobias C. Rittweiler on 2010-09-05
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

OPEN passes :AUTO-CLOSE T to MAKE-FD-STREAM, resulting in the creation
of a finalizer for the stream which closes the underlying file descriptor in case
it has not when the stream will be garbaged collected.

I think that is not a good thing to do (by default anyway) because it postpones
fd leakage problems, and makes them harder to track down.

Sounds reasonable to me. Maybe the finalizer could warn though or
print a message as it does with #!+sb-show.

Tobias C. Rittweiler (tcr) wrote :

I'd think :AUTO-CLOSE should be keyword parameter of OPEN, defaulting to
*STREAM-AUTO-CLOSE-BEHAVIOUR* which is NIL by default, but
can also be T, :WARN, and :ERROR.

James Y Knight (foom) wrote :

Wait, what? You think it should keep the FD open forever instead? Sounds like a terrible idea.

It sounds like you're asking for debugging assistance; it seems to me that all you really need is for the lambda to become a named function so you can call 'trace' on it.

Stig Hemmer (stighemmer) wrote :

It seems to me that AUTO-CLOSE doesn't postpone fd leakage problems, but solves them.

Paul Khuong (pvk) wrote :

It only solves them by accident, if the application triggers full-enough GCs at the right frequency.

Tobias C. Rittweiler (tcr) wrote :

James: What lambda?

James Y Knight (foom) wrote :

Sorry: the finalizer's:

    (when (and auto-close (fboundp 'finalize))
      (finalize stream
                (lambda ()
                  (sb!unix:unix-close fd)
                  (format *terminal-io* "** closed file descriptor ~W **~%"
                :dont-save t))

I meant, if it was something like this:

(defun finalize-close-fd (fd)
  (sb!unix:unix-close fd)
  (format *terminal-io* "** closed file descriptor ~W **~%"
      (finalize stream
                (lambda ()
                  (finalize-close-fd fd))
                :dont-save t))

You could easily do (trace sb-impl::finalize-close-fd :break t).

Nikodemus Siivola (nikodemus) wrote :

I agree that it should be easier to debug such potential FD leaks, however this is exactly implemented.

Changed in sbcl:
importance: Undecided → Low
status: New → Triaged
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers