Debian Bug report logs - #642504
bash: file number exhaustion on certain redirections in loop: "Too many open files"

version graph

Package: bash; Maintainer for bash is Matthias Klose <doko@debian.org>; Source for bash is src:bash (PTS, buildd, popcon).

Reported by: Valentin Hilbig <debian-bug-reply@03.softkill.org>

Date: Fri, 23 Sep 2011 06:30:01 UTC

Severity: normal

Found in versions 4.1-3, bash/5.2.21-2

Reply or subscribe to this bug.

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


Report forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>:
Bug#642504; Package bash. (Fri, 23 Sep 2011 06:30:04 GMT) (full text, mbox, link).


Acknowledgement sent to Valentin Hilbig <debian-bug-reply@03.softkill.org>:
New Bug report received and forwarded. Copy sent to Matthias Klose <doko@debian.org>. (Fri, 23 Sep 2011 06:30:04 GMT) (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Valentin Hilbig <debian-bug-reply@03.softkill.org>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: bash: file number exhaustion on certain redirections in loop: "Too many open files"
Date: Fri, 23 Sep 2011 08:22:35 +0200
Package: bash
Version: 4.1-3
Severity: normal


Attached is bashbug.sh which shows a strange bug in bash - with workaround.

The problem seems to be that certain redirections are not closed in-time,
leading to a possible exhaustion of file descriptors when doing this
redirection in a loop.

The strange thing about this is, that the file descriptors are closed
later, when it is already too late.

There is a workaround, this is to close the redirection manually.
However technically this is wrong, as at the time of the close the
redirection is no more in effect.

Possibly this is an upstream problem, I did not test it.

-- System Information:
Debian Release: 6.0.2
  APT prefers oldstable
  APT policy: (500, 'oldstable'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-686 (SMP w/1 CPU core)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash

Versions of packages bash depends on:
ii  base-files                6.0squeeze2    Debian base system miscellaneous f
ii  dash                      0.5.5.1-7.4    POSIX-compliant shell
ii  debianutils               3.4            Miscellaneous utilities specific t
ii  libc6                     2.11.2-10      Embedded GNU C Library: Shared lib
ii  libncurses5               5.7+20100313-5 shared libraries for terminal hand

Versions of packages bash recommends:
pn  bash-completion               <none>     (no description available)

Versions of packages bash suggests:
pn  bash-doc                      <none>     (no description available)

-- no debconf information

*** bashbug.sh
#!/bin/bash
#
# Out of file descriptors, because it forgets to close redirection

bug()
{
c=`ulimit -n`
let c+=100
while let c--
do
	while read -ru3 x
	do
		echo -n :
	done 3< <(echo x)

	# Workaround:
	# Explicite close of redirection
	$1 || exec 3<&-
done
}

works()
{
c=`ulimit -n`
let c+=100
while let c--
do
	while read -ru3 x
	do
		echo -n :
	done 3<<<"x"
done
}


echo "triggering bug"
bug true

echo "run with bug workaround"
bug false

echo "different redirection"
works




Information forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>:
Bug#642504; Package bash. (Fri, 26 Apr 2024 18:57:02 GMT) (full text, mbox, link).


Acknowledgement sent to Antoine Beaupré <anarcat@debian.org>:
Extra info received and forwarded to list. Copy sent to Matthias Klose <doko@debian.org>. (Fri, 26 Apr 2024 18:57:02 GMT) (full text, mbox, link).


Message #10 received at 642504@bugs.debian.org (full text, mbox, reply):

From: Antoine Beaupré <anarcat@debian.org>
To: Valentin Hilbig <debian-bug-reply@03.softkill.org>, 642504@bugs.debian.org
Subject: Re: Bug#642504: bash: file number exhaustion on certain redirections in loop: "Too many open files"
Date: Fri, 26 Apr 2024 14:47:29 -0400
I saw a similar crash here, where bash would start failing around about
500 iterations in such a loop:

```
export GIT_ASKPASS=echo

grep -v '^#' ../gitolite2gitlab.txt |while read gitolite_path gitlab_path; do
    gitolite_url=/srv/git.torproject.org/repositories/$gitolite_path.git 
    gitlab_url=https://gitlab.torproject.org/$gitlab_path.git 
    echo "diff -u $gitolite_url $gitlab_url"
    diff -u <(git ls-remote $gitolite_url) <(git ls-remote $gitlab_url)
done | tee final-remote-diff.patch
```

~500 is not a random number. it's about half of 1024, which i suspect is
the fd limit i'm hitting. i'm betting the shell is just not closing
those file descriptor at all after the pipeline completes.

normally, i would expect the FD to close after the `diff -u` command
returns there, but it seems that's just not happening.



Marked as found in versions bash/5.2.21-2. Request was from Gioele Barabucci <gioele@svario.it> to control@bugs.debian.org. (Sat, 27 Apr 2024 12:00:05 GMT) (full text, mbox, link).


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Thu Nov 21 22:24:52 2024; Machine Name: bembo

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.