Skip Menu |

This queue is for tickets about the IPC-Run3 CPAN distribution.

Report information
The Basics
Id: 15003
Status: resolved
Priority: 0/
Queue: IPC-Run3

People
Owner: RSCHUPP [...] cpan.org
Requestors: schupp [...] argumentum.de
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.031
Fixed in: (no value)



Subject: Data corruption with fork when both parent and child use run3
When your program calls run3, then forks and both parent and child continue to call run3, they may mix up their data. The reason is the cache of temp filehandles (%fh_cache) that IPC::Run3 uses. It gets inherited by fork, so parent and child will read/write to the same temp files and overwrite each others data. Suggested fix attached: remember the current pid to detect (on the next call to run3) that a fork has occurred; clear the cache in this case.
--- Run3.pm.orig 2005-10-11 11:33:51.770793000 +0200 +++ Run3.pm 2005-10-11 11:48:22.205958000 +0200 @@ -164,6 +164,7 @@ # We cache the handles of our temp files in order to # keep from having to incur the (largish) overhead of File::Temp my %fh_cache; +my $fh_cache_pid = $$; my $profiler; @@ -423,6 +424,13 @@ my $out_type = _type $stdout; my $err_type = _type $stderr; + if ($fh_cache_pid != $$) { + # fork detected, close all cached filehandles and clear the cache + close $_ foreach values %fh_cache; + %fh_cache = (); + $fh_cache_pid = $$; + } + # This routine procedes in stages so that a failure in an early # stage prevents later stages from running, and thus from needing # cleanup.
Date: Tue, 11 Oct 2005 16:21:15 -0400
From: Barrie Slaymaker <barries [...] slaysys.com>
Subject: Re: [cpan #15003] Data corruption with fork when both parent and child use run3
To: bug-IPC-Run3 [...] rt.cpan.org
CC: undisclosed-recipients:;
RT-Send-Cc:
How about clearing the cache in the child process only just after it is forked? If you could send a patch.... - Barrie via RT wrote: Show quoted text
>This message about IPC-Run3 was sent to you by RSCHUPP <RSCHUPP@cpan.org> via rt.cpan.org > >Full context and any attached attachments can be found at: ><URL: https://rt.cpan.org/Ticket/Display.html?id=15003 > > >When your program calls run3, then forks and both parent and >child continue to call run3, they may mix up their data. > >The reason is the cache of temp filehandles (%fh_cache) that >IPC::Run3 uses. It gets inherited by fork, so parent and child >will read/write to the same temp files and overwrite each others data. >Suggested fix attached: remember the current pid to detect (on the >next call to run3) that a fork has occurred; clear the cache in this case. > >