Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

5 views
Skip to first unread message

Bo Johansson

unread,
Apr 8, 2011, 4:47:19 AM4/8/11
to bugs-bi...@rt.perl.org
# New Ticket Created by "Bo Johansson"
# Please include the string: [perl #88080]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=88080 >


This is a bug report for perl from bo.joh...@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

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=low
---
Site configuration information for perl 5.12.2:

Configured by 1 at Fri Nov 5 08:33:05 2010.

Summary of my perl5 (revision 5 version 12 subversion 2) configuration:

Platform:
osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
uname='Win32 strawberryperl 5.12.2.0 #1 Fri Nov 5 05:17:27 2010 i386'
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields -DPERL_MSVCRT_READFIX',
optimize='-s -O2',
cppflags='-DWIN32'
ccversion='', gccversion='4.4.3', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'
libpth=C:\strawberry\c\lib C:\strawberry\c\i686-w64-mingw32\lib
libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
libc=, so=dll, useshrplib=true, libperl=libperl512.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'

Locally applied patches:

---
@INC for perl 5.12.2:
C:/strawberry/perl/site/lib
C:/strawberry/perl/vendor/lib
C:/strawberry/perl/lib
.

---
Environment for perl 5.12.2:
HOME (unset)
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\ArcSoft\Bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;c:\Parrot-2.8.0\bin;S:\ins\ant\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;c:\Program Files\Emacs\EmacsW32\gnuwin32\bin\;c:\Program Files\Java\jdk1.6.0_16\bin;C:\hp\bin\Python;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Graphviz2.26.3\bin;C:\strawberry\c\bin;C:\strawberry\perl\bin;C:\gnuwin32\bin;C:\Parrot-2.8.0\bin;C:\Parrot-2.8.0\bin;C:\Program Files\Windows Live\Shared;C:\Program Files\QuickTime\QTSystem\;C:\strawberry\perl\site\bin;C:\Program Files\Microsoft Windows Performance Toolkit\;C:\Program Files\Git\cmd
PERL_BADLANG (unset)
SHELL (unset)

James E Keenan via RT

unread,
Dec 31, 2016, 10:30:02 AM12/31/16
to perl5-...@perl.org
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.

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

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

Bo Johansson

unread,
Jan 1, 2017, 5:45:02 AM1/1/17
to perlbug-...@perl.org

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

James E Keenan via RT

unread,
Jan 1, 2017, 1:15:01 PM1/1/17
to perl5-...@perl.org
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 (jke...@cpan.org)

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