Where's my CGI hook going?

C

Carsten Broschek

Hi,

After looking at
http://search.cpan.org/~lgoddard/CGI-ProgressBar-0.04/ProgressBar.pm
I tried to show the upload-process from a multipart-request via
callback: my $cgi = CGI->new(\&bar_hook, $data);

For me it seems, that the processes does not end, as well a Testing of
the ProgressBar.pm shows endless processing. Are there know problems
with the callback-feature or is my code stupid?

[...]
my $data;
my $hook_called;
my $cgi = CGI->new(\&bar_hook, $data);

[...]
sub bar_hook
{
my ($filename, $buffer, $bytes, $data) = @_;
if (not $hook_called)
{
print header,
start_html( -title=>'Simple Upload-hook Example'),
h1('Uploading'),
p( "Have to read <var>$filename</var> Size
<var>$ENV{CONTENT_LENGTH}</var>"),
hr;
$hook_called = 1;
}
else
{
print "Content Length [$ENV{CONTENT_LENGTH}] <br>bytes_read
[$bytes] sum [$hook_called]...";
}
$hook_called += $bytes;
}

Response shows:
Uploading

Have to read ascotel_01.jpg Size 95127
Content Length [95127]
bytes_read [4155] sum [4039]...Content Length [95127]
bytes_read [4155] sum [8194]...Content Length [95127]
bytes_read [4155] sum [12349]...Content Length [95127]
bytes_read [4155] sum [16504]...Content Length [95127]
bytes_read [4155] sum [20659]...Content Length [95127]
bytes_read [4155] sum [24814]...Content Length [95127]
bytes_read [4155] sum [28969]...Content Length [95127]
bytes_read [4155] sum [33124]...Content Length [95127]
bytes_read [4155] sum [37279]...Content Length [95127]
bytes_read [4155] sum [41434]...Content Length [95127]
[... lot of more lines]

After some seconds logfile gets:
[Wed May 10 18:27:53 2006] [error] [client 192.168.1.3] CGI.pm: Server
closed socket during multipart read (client aborted?)., referer:
http://192.168.1.3:12080/cgi-bin/hookme.cgi


Thanks for hints in advance,

CARSTEN
 
X

xhoster

Carsten Broschek said:
Hi,

After looking at
http://search.cpan.org/~lgoddard/CGI-ProgressBar-0.04/ProgressBar.pm
I tried to show the upload-process from a multipart-request via
callback: my $cgi = CGI->new(\&bar_hook, $data);

For me it seems, that the processes does not end, as well a Testing of
the ProgressBar.pm shows endless processing. Are there know problems
with the callback-feature or is my code stupid?

I'm guessing neither. What happens if you take out the callback?
Probably you will get the same error at the end, just without all
the intermediate messages printed out by the callback.

From CGI.pm:


# An apparent bug in the Apache server causes the read()
# to return zero bytes repeatedly without blocking if the
# remote user aborts during a file transfer. I don't know how
# they manage this, but the workaround is to abort if we get
# more than SPIN_LOOP_MAX consecutive zero reads.
if ($bytesRead == 0) {
die "CGI.pm: Server closed socket during multipart read (client
aborted?).\n"
if ($self->{ZERO_LOOP_COUNTER}++ >= $SPIN_LOOP_MAX);
} else {
$self->{ZERO_LOOP_COUNTER}=0;
}


Xho
 
X

xhoster

I'm guessing neither. What happens if you take out the callback?
Probably you will get the same error at the end, just without all
the intermediate messages printed out by the callback.

OK, I guessed wrong.

What is happening is that the browser (or the http server on behalf of the
browser, I'm not sure which) refuses to read the response from the CGI
until the entire request has been delivered. So once upload_hook has
printed out one entire buffer worth of information, the print in the hook
blocks waiting for the server/browser to start reading the response, while
the server/browser is blocked waiting for the CGI script to finish reading
the request. Bang, deadlock. This goes until the browser/server times
out. Once the timeout happens, then the code I posted previously kicks in,
and you get 2000 messages with the same size before CGI.pm gives up and
dies.

The moral of the story is that I don't think you can't do the progress bar
thing without having more than one http connection open. Sorry for
misleading you last about that last week.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top