mifflin has asked for the wisdom of the Perl Monks concerning the following question:

I'm using HTTP::Deamon to put together a web service. I'm running into a situation where a client makes a request and then immediately disconnects. The server gets the request and then trys to respond. The first 'print' statement back to the client is in HTTP::Daemon::ClientConn::send_status_line. When the print statement executes that sends header info back to the client the program just stops.
No exceptions are raised that can be caught with an eval.
No core dumps happen.
None of my END blocks execute.

Below is a code snippet in HTTP::Deamon::ClientConn.
To 'help' me debug this I put two print statements to stdout before and after the print statement of header info back to the client.
The first statement prints.
The second never does.
sub send_status_line { my($self, $status, $message, $proto) = @_; return if $self->antique_client; $status ||= RC_OK; $message ||= status_message($status) || ""; $proto ||= $HTTP::Daemon::PROTO || "HTTP/1.1"; print STDOUT "$$ ",__PACKAGE__,"::send_status_line before print\n" +; print $self "$proto $status $message$CRLF"; print STDOUT "$$ ",__PACKAGE__,"::send_status_line after print\n"; }
Any ideas?

Using perl 5.8 on A sun box
% uname -a
SunOS odin 5.6 Generic_105181-35 sun4u sparc SUNW,Ultra-4

Replies are listed 'Best First'.
Re: HTTP::Daemon aborting in send_status_line?
by sgifford (Prior) on Apr 23, 2004 at 02:58 UTC

    The print statement is probably blocking. One reason for that could be that the socket went away and you were told by the failure of a system call, but you didn't handle the error. Can you reproduce this problem with the small sample server that comes with HTTP::Daemon? (I wasn't able to) Can you try to whittle your program down to the smallest section that demonstrates the problem and post that?

    In particular, it looks like this might be the effect you'd see if you didn't check the return status from the get_request method.

      I thought I did just that.
      That sub in my original post is in HTTP::Daemon::ClientConn
      How would check the return status of a print statement?

      update

      I've even tried putting in an eval block directly in that sub like...

      sub send_status_line { my($self, $status, $message, $proto) = @_; return if $self->antique_client; $status ||= RC_OK; $message ||= status_message($status) || ""; $proto ||= $HTTP::Daemon::PROTO || "HTTP/1.1"; print STDOUT "$$ ",__PACKAGE__,"::send_status_line before print\n" +; eval { print $self "$proto $status $message$CRLF"; }; if ($@) { print STDOUT "$$ ",__PACKAGE__,"::send_status_line caught excep +tion $@\n"; } print STDOUT "$$ ",__PACKAGE__,"::send_status_line after print\n"; }

      but that line never prints either

        Well, you can check the return value from print just like anything else:

        print "hello there\n" or die "print failed: $!\n";

        It's possible, though, that the print statement isn't failing, but is just blocking, waiting for the socket to become writable. Since this will never happen, it will wait forever.

        Whether this is happening will depend on the state of the socket when send_status_line is entered, so you'll need to show us more code---ideally, the smallest amount of code that still exhibits the error.

Re: HTTP::Daemon aborting in send_status_line?
by Belgarion (Chaplain) on Apr 23, 2004 at 01:22 UTC

    I can not give you an answer, unfortunately, but I can provide a few more data points. I'm experienced the same problem running under Linux with perl 5.8.2. However, when I run the exact same code under Windows using perl 5.8 I don't have the problem!

    For example, under Linux and using Mozilla, when I reload a page served by my HTTP::Daemon derived class too quickly the process dies without any error messages. Under Windows, quickly reloading does not cause any problems. I have no idea why this would be the case, but maybe my experience will help someone diagnose the problem.