[darcs-devel] Race in darcs.cgi

Will will at glozer.net
Wed Sep 29 15:07:40 PDT 2004


Hi David D., Andrew,

Thanks for the bug report, analysis, and patch!  I'll apply this
change and submit it to the darcs repo.

Thanks,
Will

"Davide Dente" <davidedente at fastmail.fm> writes:

> On Tue, 28 Sep 2004 16:29:24 -0400, "Andrew Pimlott"
> <andrew at pimlott.net> said:
>
>> On Mon, Sep 27, 2004 at 12:14:48PM +0200, Davide Dente wrote:
>> > The problem is that I have xsltproc trying to read the tempfile *after*
>> > it has been created but *before* anything has been written to it. This
>> > is because perl invoked by CGI does not autoflush the files, and my
>> > server is probably to slow (SUN Ultra 60, Solaris 2.6, Perl 5.6.1).
>> 
>> This analysis is not quite right, although I'm sure your patch fixes the
>> problem.  xsltproc fails to see the (whole) xml document not because of
>> a race condition (all output to the temporary file is done synchronously
>> before xsltproc is called), but because some of the output is still
>> buffered by perl.
>
> Yes, this is what I did mean when I said 'race'; the problem is not in
> the script itself, but in the way perl buffer the output when invoked as
> a CGI script.
>
>
>> So a more clear and efficient solution is to add a
>> flush to finish_xml.  
>
> You are right, this would be more efficent. Here is a new diff:
>
> ----------------
> diff -Naur darcs.cgi darcs.cgi.dd
> --- darcs.cgi   2004-09-24 19:18:04.803338000 +0200
> +++ darcs.cgi.dd        2004-09-29 11:38:45.101917000 +0200
> @@ -36,6 +36,7 @@
>  use File::Basename;
>  use File::stat;
>  use File::Temp;
> +use IO::Handle;
>  use POSIX;
>  
>  ## the following variables can be customized to reflect your system
> @@ -151,6 +152,7 @@
>  sub finish_xml {
>      my ($fh) = @_;
>      print $fh "\n</darcs>\n";
> +    $fh->flush;
>  }
>  
>  # run a darcs command and return a file handle for the output
> ----------------
>
> [Sorry for not sending a darcs patch, I'm still learning it, and I've
> got some problem making it work]
>
> HTH,
> dd




More information about the darcs-devel mailing list