develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #119003] Simple threaded server crashes on Windows XP/7 and native Perl

Thread Next
From:
Piotr Roszatycki
Date:
July 24, 2013 15:45
Subject:
[perl #119003] Simple threaded server crashes on Windows XP/7 and native Perl
Message ID:
rt-3.6.HEAD-2552-1374661903-643.119003-75-0@perl.org
# New Ticket Created by  Piotr Roszatycki 
# Please include the string:  [perl #119003]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=119003 >


This is a bug report for perl from dexter@cpan.org,
generated with the help of perlbug 1.39 running under perl 5.18.0.


-----------------------------------------------------------------
[Please describe your issue here]

The server is:

#!/usr/bin/perl

use strict;

use threads;

use IO::Socket;
use Socket qw(IPPROTO_TCP TCP_NODELAY);

sub process_connection {
    my ($sock) = @_;

    $sock->setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
        or die "setsockopt(TCP_NODELAY) failed:$!";

    while (my $line = <$sock>) {
        $line =~ s/\015?\012$//;
        if ($line =~ /^$/) {
            print $sock "HTTP/1.0 200 OK\015\012Content-Type:
text/plain\015\012\015\012Hello, world!\015\012";
            last;
        };
    };
    close $sock;
}

my $server = IO::Socket::INET->new( LocalPort => 5000, Type =>
SOCK_STREAM, Reuse => 1, Listen => SOMAXCONN ) or die ("bind: $!\n");

warn $server;

sub worker {
    my ($n, $server) = @_;
    while(my $client = $server->accept) {
        process_connection($client);
    }
}

for my $n (1..20) {
    my $thr = threads->create(\&worker, $n, $server);
}

foreach my $thr (threads->list) {
    $thr->join;
}


The client is:

ab -c 1 -n 1000 http://localhost:5000/


The test fail on Windows XP/7 (MSWin32). It handles a few requests and
throws error:

Thread 4 terminated abnormally: setsockopt(TCP_NODELAY) failed:An operation was
attempted on something that is not a socket. at server-pre-threads.pl line 13.

The test passed on Windows 2003/8 (MSWin32) or ealier (cygwin).


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

Configured by strawberry-perl at Sat May 18 17:47:09 2013.

Summary of my perl5 (revision 5 version 18 subversion 0) configuration:

  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread-64int
    uname='Win32 strawberry-perl 5.18.0.1 #1 Sat May 18 17:46:00 2013 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=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags =' -s -O2 -DWIN32  -DPERL_TEXTMODE_SCRIPTS
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO
-fno-strict-aliasing -mms-bitfields',
    optimize='-s -O2',
    cppflags='-DWIN32'
    ccversion='', gccversion='4.6.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, 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=libperl518.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.18.0:
    C:/strawberry/perl/site/lib/MSWin32-x86-multi-thread-64int
    C:/strawberry/perl/site/lib
    C:/strawberry/perl/vendor/lib
    C:/strawberry/perl/lib
    .

---
Environment for perl 5.18.0:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin
    PERL_BADLANG (unset)
    SHELL (unset)


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