develooper Front page | perl.perl5.porters | Postings from January 2017

[perl #88080] Listen to socket does not return when host isundefined or 0.0.0.0.

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
January 1, 2017 18:07
Subject:
[perl #88080] Listen to socket does not return when host isundefined or 0.0.0.0.
Message ID:
rt-4.0.24-26163-1483294012-1682.88080-15-0@perl.org
On Sun, 01 Jan 2017 10:36:01 GMT, boilund wrote:
> Hej!
> 
> I have run:
> 
> use strict;
> use warnings;
> 
> use HTTP::Server::Simple;
> 
> my $server = HTTP::Server::Simple->new();
> $server->host( undef );
> #$server->host( '0.0.0.0' );
> $server->run();
> 
> Using "$server->host( undef );" or "$server->host( '0.0.0.0' );" works
> with HTTP::Server::Simple version 0.51!
> 
> Best regards
> Bo Johansson
> 
> Den 2016-12-31 kl. 16:14, skrev James E Keenan via RT:
> > On Fri, 08 Apr 2011 08:47:19 GMT, boilund wrote:
> >> This is a bug report for perl from bo.johansson@lsn.se,
> >> generated with the help of perlbug 1.39 running under perl 5.12.2.
> >>
> >>
> >> -----------------------------------------------------------------
> >> [Please describe your issue here]
> >>
> >> The perl function listen does not return when host is undefined or
> >> 0.0.0.0.
> >> Sometimes it also gets Windows 7 in unstable state and normal shut
> >> down is impossible.
> >>
> >> Example: This is setup_listener from HTTP-Server-Simple-
> >> 0.44/lib/HTTP/Server/Simple.pm
> >>
> >> sub setup_listener {
> >>      my $self = shift;
> >>
> >> my $tcp = getprotobyname('tcp');
> >> socket( HTTPDaemon, PF_INET, SOCK_STREAM, $tcp ) or croak "socket:
> >> $!";
> >> setsockopt( HTTPDaemon, SOL_SOCKET, SO_REUSEADDR, pack( "l", 1 ) )
> >>      or warn "setsockopt: $!";
> >> bind( HTTPDaemon,
> >>      sockaddr_in(
> >>          $self->port(),
> >>          (   $self->host
> >>              ? inet_aton( $self->host )
> >>              : INADDR_ANY
> >>          )
> >>      )
> >>      )
> >>      or croak "bind to @{[$self->host||'*']}:@{[$self->port]}: $!";
> >> listen( HTTPDaemon, SOMAXCONN ) or croak "listen: $!";
> >> }
> >>
> >> If $self->host is undefined or '0.0.0.0' the call to listen does not
> >> return.
> >>    Sometimes it gets Windows 7 in unstable state and
> >>
> > Can the problem with Perl function 'listen' (assuming there *is* a
> > problem) be demonstrated apart from this use in HTTP::Server::Simple?
> >
> > The code provided is not sufficient to reproduce the problem (at
> > least by a person not already familiar with that module).
> >
> > Thank you very much.
> >

I modified HTTP::Server::Simple::setup_listener() to capture the return value of 'listen()' before returning from the method.

#####
    my $rv = listen( HTTPDaemon, SOMAXCONN ) or croak "listen: $!";
    return $rv;
#####

I then called your program -- with '$server->host(undef)' -- with the perl debugger and stepped through to the lines above.  The value of '$rv' is '1', so listen() returned a true value.

Where the program *did* hang was in this part of subroutine '_default_run(()':

#####
        while ($SERVER_SHOULD_RUN) {
            local $SIG{PIPE} = 'IGNORE';    # If we don't ignore SIGPIPE, a
                 # client closing the connection before we
                 # finish sending will cause the server to exit
            while ( accept( my $remote = new FileHandle, HTTPDaemon ) ) {
#####

The program hung on the 2nd 'while' loop.  When I hit Ctrl-C, the program resumed at the 'local $SIG{PIPE}...' line.

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=88080

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About