zsh-workers
 help / color / mirror / code / Atom feed
* Combination of pipes and &! leaks file descriptors
@ 2017-05-02 14:19 ` Jure Varlec
  2017-05-03 10:04   ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Jure Varlec @ 2017-05-02 14:19 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 542 bytes --]

Hello,

I noticed a file descriptor leak today in a script that was forking
jobs in a loop and ceased to work after 1000 jobs. A (quick, admittedly)
search of the mailing list found nothing relevant. A minimal example is
attached, using `lsof` to demonstrate the problem. I also attached its
output in case there are difficulties reproducing the problem. It is
interesting to see that only the `&!` operator causes the problem, the
`disown` command does not. A pipe needs to be present in the
backgrounded command.

Regards
Jure

[-- Attachment #1.2: forkleak.sh --]
[-- Type: application/x-shellscript, Size: 422 bytes --]

[-- Attachment #1.3: Type: text/plain, Size: 1898 bytes --]

Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=forkleak.out

V2l0aCB0aGVgZGlzb3duYCBrZXl3b3JkOgoxYzEKPCBmb3JrbGVhay4gMjcwNjYgZXh6b21iaWUg
ICAxN3IgIEZJRk8gICAgICAgICAgICAgICAwLDEwICAgICAgMHQwICAxOTg4ODE5IHBpcGUgMjcw
NjcsZm9ya2xlYWsuLDF3IDI3MDY5LGdyZXAsMXcKLS0tCj4gZm9ya2xlYWsuIDI3MDY2IGV4em9t
YmllICAgMTdyICBGSUZPICAgICAgICAgICAgICAgMCwxMCAgICAgIDB0MCAgMTk4OTA5MSBwaXBl
IDI3MDkyLGZvcmtsZWFrLiwxdyAyNzA5NCxncmVwLDF3CgpXaXRoIHRoZSBgJiFgIG9wZXJhdG9y
OgoxYzEsMTEKPCBmb3JrbGVhay4gMjcwNjYgZXh6b21iaWUgICAxN3IgIEZJRk8gICAgICAgICAg
ICAgICAwLDEwICAgICAgMHQwICAxOTg4ODE5IHBpcGUgMjcwNjcsZm9ya2xlYWsuLDF3IDI3MDY5
LGdyZXAsMXcKLS0tCj4gZm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ICAgMjdy
ICBGSUZPICAgICAgICAgICAgICAgMCwxMCAgICAgIDB0MCAgMTk4MzI0MiBwaXBlIDI3MTE3LGZv
cmtsZWFrLiwxdyAyNzExOSxncmVwLDF3Cg==

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Combination of pipes and &! leaks file descriptors
  2017-05-02 14:19 ` Combination of pipes and &! leaks file descriptors Jure Varlec
@ 2017-05-03 10:04   ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2017-05-03 10:04 UTC (permalink / raw)
  To: Jure Varlec, zsh-workers

On Tue, 2 May 2017 16:19:25 +0200
Jure Varlec <jure@varlec.si> wrote:
> I noticed a file descriptor leak today in a script that was forking
> jobs in a loop and ceased to work after 1000 jobs. A (quick, admittedly)
> search of the mailing list found nothing relevant. A minimal example is
> attached, using `lsof` to demonstrate the problem. I also attached its
> output in case there are difficulties reproducing the problem. It is
> interesting to see that only the `&!` operator causes the problem, the
> `disown` command does not. A pipe needs to be present in the
> backgrounded command.

Thanks, this made it easy to track down.

pws

diff --git a/Src/exec.c b/Src/exec.c
index 9a75dd2..debb0ae 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1612,6 +1612,7 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 	    zclose(opipe[0]);
 	}
 	if (how & Z_DISOWN) {
+	    pipecleanfilelist(jobtab[thisjob].filelist, 0);
 	    deletejob(jobtab + thisjob, 1);
 	    thisjob = -1;
 	}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-03 10:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170502142014epcas2p3a442db31cf0a8c28b27e89a4cf188e10@epcas2p3.samsung.com>
2017-05-02 14:19 ` Combination of pipes and &! leaks file descriptors Jure Varlec
2017-05-03 10:04   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).