GNU bug report logs - #72092
popen creates "/dev/null" fds and never closes them

Previous Next

Package: guile;

Reported by: jakub-w <at> riseup.net

Date: Sat, 13 Jul 2024 12:09:02 UTC

Severity: important

To reply to this bug, email your comments to 72092 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#72092; Package guile. (Sat, 13 Jul 2024 12:09:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to jakub-w <at> riseup.net:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 13 Jul 2024 12:09:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: jakub-w <at> riseup.net
To: bug-guile <at> gnu.org
Subject: popen creates "/dev/null" fds and never closes them
Date: Sat, 13 Jul 2024 12:07:52 +0000
Consider the following example:

(use-modules (ice-9 popen))

(parameterize ((current-error-port (%make-void-port OPEN_BOTH)))
  (while #t
    (close-pipe (open-pipe* OPEN_READ "free"))
    (sleep 1)))

This opens a new "/dev/null" file descriptor every second and doesn't
close it when close-pipe is called.
If current ports are all fd ports, this doesn't happen.

AFAICT the problem was introduced by the commit
36fd2b4920ae926c79b936c29e739e71a6dff2bc in Guile 3.0.10.




Information forwarded to bug-guile <at> gnu.org:
bug#72092; Package guile. (Sat, 13 Jul 2024 18:24:02 GMT) Full text and rfc822 format available.

Message #8 received at 72092 <at> debbugs.gnu.org (full text, mbox):

From: nathan <nathan_mail <at> nborghese.com>
To: 72092 <at> debbugs.gnu.org, jakub-w <at> riseup.net
Subject: [PATCH] fix file descriptor leak in piped_process/system*/popen/etc
Date: Sat, 13 Jul 2024 18:22:58 +0000
[Message part 1 (text/plain, inline)]
fix is attached

test code:
(use-modules (ice-9 ftw))
(use-modules (ice-9 popen))
(define (print-open)
   (format #t "~a\n" (length (scandir "/proc/self/fd"))))
(let ((p (%make-void-port "rw")))
   (print-open)
   (parameterize ((current-output-port p) (current-input-port p) (current-error-port p))
     (system* "ls"))
   (close-port p)
   (print-open))
(parameterize ((current-error-port (%make-void-port OPEN_BOTH)))
     (while
      #t
      (close-pipe (open-pipe* OPEN_READ "free"))
      (print-open)
      (sleep 1)))

there's still a one-time increase in the file descriptors, but it seems unrelated. or at least much harder to find.

(by the way, ignoring current-output-port and using /dev/null is bad. it would be nice to open a pipe in that case and forward whatever the child writes to the scheme port.
but that would require a separate thread, and it may be impossible to do something like that for current-input-port)
[0001-fix-file-descriptor-leak-in-piped_process-system-pop.patch (text/x-patch, attachment)]

Severity set to 'important' from 'normal' Request was from Ludovic Courtès <ludo <at> gnu.org> to control <at> debbugs.gnu.org. (Fri, 27 Sep 2024 20:35:01 GMT) Full text and rfc822 format available.

This bug report was last modified 56 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.