fd-closing finalizer on streams considered unwarranted

Bug #630680 reported by Tobias C. Rittweiler
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Triaged
Low
Unassigned

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.

Revision history for this message
Gábor Melis (melisgl) wrote : Re: [Bug 630680] [NEW] fd-closing finalizer on streams considered unwarranted

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

Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
Stig Hemmer (stighemmer) wrote :

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

Revision history for this message
Paul Khuong (pvk) wrote :

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

Revision history for this message
Tobias C. Rittweiler (tcr) wrote :

James: What lambda?

Revision history for this message
James Y Knight (foom) wrote :

Sorry: the finalizer's:

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

I meant, if it was something like this:

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

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

Revision history for this message
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  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.