Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fork + socketpair) x 2 doesn't work under Windows, works under Linux #9724

Open
p5pRT opened this issue Apr 25, 2009 · 8 comments
Open

(fork + socketpair) x 2 doesn't work under Windows, works under Linux #9724

p5pRT opened this issue Apr 25, 2009 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 25, 2009

Migrated from rt.perl.org#65136 (status was 'open')

Searchable as RT65136$

@p5pRT
Copy link
Author

p5pRT commented Apr 25, 2009

From sergstesh@yahoo.com

Created by sergei@amdam2.site

All the details can be found here​:

http​://bugs.activestate.com/show_bug.cgi?id=82846#comments
.

Perl Info

Flags:
    category=core
    severity=critical

Site configuration information for perl 5.10.0:

Configured by sergei at Wed Mar 11 09:35:43 IST 2009.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.22.19-0.2-default, archname=i686-linux-thread-multi
    uname='linux amdam2 2.6.22.19-0.2-default #1 smp 2008-12-18 10:17:03 +0100 i686 athlon i386 gnulinux '
    config_args='-des -Dprefix=/home/sergei/PERL-5.10.0 -Dusethreads -Dcc=/mnt/sdb8/sergei/AFSWD_debug/install/gcc-4.3.3/binsh/gcc'
    hint=recommended, useposix=true, d_sigaction=define
    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='/mnt/sdb8/sergei/AFSWD_debug/install/gcc-4.3.3/binsh/gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='4.3.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='/mnt/sdb8/sergei/AFSWD_debug/install/gcc-4.3.3/binsh/gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.6.1.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.6.1'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.10.0:
    /home/sergei/PERL-5.10.0/lib/perl5/5.10.0/i686-linux-thread-multi
    /home/sergei/PERL-5.10.0/lib/perl5/5.10.0
    /home/sergei/PERL-5.10.0/lib/perl5/site_perl/5.10.0/i686-linux-thread-multi
    /home/sergei/PERL-5.10.0/lib/perl5/site_perl/5.10.0
    .


Environment for perl 5.10.0:
    HOME=/home/sergei
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/opt/kde3/bin:/home/sergei/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash



      

@p5pRT
Copy link
Author

p5pRT commented Aug 14, 2012

From @jkeenan

On Sat Apr 25 16​:05​:28 2009, sergstesh wrote​:

This is a bug report for perl from sergei@​amdam2.site,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
[Please enter your report here]

All the details can be found here​:

http​://bugs.activestate.com/show_bug.cgi?id=82846#comments
.

P5P list​:

The original bug report provided no details but instead only referred
the reader to an outside bug tracker. This is perhaps why no one has
responded to this report in three-plus years.

http​://bugs.activestate.com/show_bug.cgi?id=82846 appears to be
unresolved. Its capsule description is​: "[A] script with nested 'fork'
and 'socketpair' is stuck under Windows, works under Linux."

How should we handle a ticket like this?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Aug 14, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jul 21, 2013

From @rjbs

* James E Keenan via RT <perlbug-followup@​perl.org> [2012-08-13T20​:07​:20]

How should we handle a ticket like this?

I think the next step is getting someone to determine whether this problem can
still be reproduced.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2013

From @bulk88

On Sun Jul 21 13​:23​:38 2013, perl.p5p@​rjbs.manxome.org wrote​:

* James E Keenan via RT <perlbug-followup@​perl.org> [2012-08-
13T20​:07​:20]

How should we handle a ticket like this?

I think the next step is getting someone to determine whether this
problem can
still be reproduced.

Reproduced in 5.19.2. This is a deadlock over locking a file handle. I
think I've seen this class of bugs and diagnosed them before on perl RT.

Main thread, according to curcop is at
_________________________________________________________________
if($pid = fork)
  {
  close $parent_fh;
  print $child_fh "Parent Pid $$ is sending this\n";
  chomp(my $line = <$child_fh>);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  warn "Parent Pid $$ just read this​: '$line'";
  close $child_fh;
  waitpid($pid,0);
  }
else
_________________________________________________________________

its TID is 5980, C callstack below
_______________________________________________________
  ntdll.dll!_KiFastSystemCallRet@​0()
  ntdll.dll!_NtReadFile@​36() + 0xc
  kernel32.dll!_ReadFile@​20() + 0x67

msvcr71.dll!_read_lk(int fh=4, void * buf=0x00ae5254, unsigned int
cnt=8192) Line 154 + 0x15 C
  msvcr71.dll!_read(int fh=4, void * buf=0x00ae5254, unsigned int
cnt=8192) Line 75 + 0xc C
  perl519.dll!PerlLIORead(IPerlLIO * piPerl=0x0036587c, int handle=4,
void * buffer=0x00ae5254, unsigned int count=8192) Line 1032 + 0x12 C
  perl519.dll!PerlIOUnix_read(interpreter * my_perl=0x00365ff4, _PerlIO
* * f=0x008f4d8c, void * vbuf=0x00ae5254, unsigned int count=8192) Line
2790 + 0x14 C
  perl519.dll!Perl_PerlIO_read(interpreter * my_perl=0x00365ff4, _PerlIO
* * f=0x008f4d8c, void * vbuf=0x00ae5254, unsigned int count=8192) Line
1679 + 0x27 C
  perl519.dll!PerlIOBuf_fill(interpreter * my_perl=0x00365ff4, _PerlIO *
* f=0x008f473c) Line 4036 + 0xb C
  perl519.dll!Perl_PerlIO_fill(interpreter * my_perl=0x00365ff4, _PerlIO
* * f=0x008f473c) Line 1776 + 0x23 C
  perl519.dll!PerlIOBase_read(interpreter * my_perl=0x00365ff4, _PerlIO
* * f=0x008f473c, void * vbuf=0x0012da4b, unsigned int count=1) Line
2170 + 0xb C
  perl519.dll!PerlIOBuf_read(interpreter * my_perl=0x00365ff4, _PerlIO *
* f=0x008f473c, void * vbuf=0x0012da4b, unsigned int count=1) Line
4057 + 0xf C
  perl519.dll!Perl_PerlIO_read(interpreter * my_perl=0x00365ff4, _PerlIO
* * f=0x008f473c, void * vbuf=0x0012da4b, unsigned int count=1) Line
1679 + 0x27 C
  perl519.dll!PerlIO_getc(_PerlIO * * f=0x008f473c) Line 4916 + 0xf C
  perl519.dll!Perl_sv_gets(interpreter * my_perl=0x00365ff4, sv * const
sv=0x0a9b1dd4, _PerlIO * * const fp=0x008f473c, long append=0) Line 8050 C
  perl519.dll!Perl_do_readline(interpreter * my_perl=0x00000400) Line
1774 + 0x12 C
  perl519.dll!Perl_runops_standard(interpreter * my_perl=0x00365ff4)
Line 42 + 0x4 C
  perl519.dll!S_run_body(interpreter * my_perl=0x00000f84, long
oldscope=1) Line 2495 + 0xa C
  perl519.dll!perl_run(interpreter * my_perl=0x00365ff4) Line 2411 + 0x8 C
  perl519.dll!RunPerl(int argc=2, char * * argv=0x01362478, char * *
env=0x00362e18) Line 270 + 0x6 C
  perl.exe!main(int argc=2, char * * argv=0x00362478, char * *
env=0x00362e18) Line 89 + 0x12 C
  perl.exe!mainCRTStartup() Line 398 + 0xe C
  kernel32.dll!_BaseProcessStart@​4() + 0x23
__________________________________________________________

next thread, this is the child thread, TID 3120, curcop
___________________________________________________________
else
  {
  {
  my $child_fh;
  my $parent_fh;
  socketpair($child_fh, $parent_fh, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
or die "socketpair​: $!";

  $child_fh->autoflush(1);
  $parent_fh->autoflush(1);
  my $pid;
  if($pid = fork)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  {
  close $parent_fh;
  print $child_fh "Parent Pid $$ is sending this\n";
  chomp(my $line = <$child_fh>);
_____________________________________________________________
callstack is
_____________________________________________________________
  ntdll.dll!_KiFastSystemCallRet@​0()
  ntdll.dll!_ZwWaitForSingleObject@​12() + 0xc
  ntdll.dll!_RtlpWaitForCriticalSection@​4() + 0x8c
  ntdll.dll!_RtlEnterCriticalSection@​4() + 0x46
  msvcr71.dll!_lock_fhandle(int fh=4) Line 453 C
  msvcr71.dll!_fstati64(int fildes=4, _stati64 * buf=0x00d8fdcc) Line
86 + 0x6 C
  perl519.dll!PerlLIOFileStat(IPerlLIO * piPerl=0x00a49844, int
handle=4, _stati64 * buffer=0x00d8fdcc) Line 971 + 0xe C
  perl519.dll!PerlIOUnix_setfd(interpreter * my_perl=0x7ffdd000, _PerlIO
* * f=0x00d8fc54, int fd=3540488, int imode=0) Line 2643 + 0x15 C
  perl519.dll!PerlIOUnix_dup(interpreter * my_perl=0x00a53404, _PerlIO *
* f=0x00a53eec, _PerlIO * * o=0x00a4849c, clone_params *
param=0x00d8feb4, int flags=1) Line 2765 + 0xf C
  perl519.dll!PerlIOBase_dup(interpreter * my_perl=0x00a53404, _PerlIO *
* f=0x00a53eec, _PerlIO * * o=0x00a48054, clone_params *
param=0x00d8feb4, int flags=1) Line 2293 C
  perl519.dll!PerlIO_fdupopen(interpreter * my_perl=0x00d8fc54, _PerlIO
* * f=0x00070023, clone_params * param=0x00d8feb4, int flags=1) Line
579 + 0x13 C
  perl519.dll!Perl_fp_dup(interpreter * my_perl=0x00a53404, _PerlIO * *
const fp=0x00a48054, const char type=0, clone_params * const
param=0x00d8feb4) Line 11617 + 0xb C
  perl519.dll!PerlIO_clone(interpreter * my_perl=0x00000000, interpreter
* proto=0x7ffdd000, clone_params * param=0x00d8feb4) Line 693 + 0xc C
  perl519.dll!perl_clone_using(interpreter * proto_perl=0x0096f024,
unsigned long flags=1, IPerlMem * ipM=0x00a4971c, IPerlMem *
ipMS=0x00000001, IPerlMem * ipMP=0x00a49754, IPerlEnv * ipE=0x00a49770,
IPerlStdIO * ipStd=0x00a497a8, IPerlLIO * ipLIO=0x00a49844, IPerlDir *
ipD=0x00a498ac, IPerlSock * ipS=0x00a498d8, IPerlProc * ipP=0x00a49988)
Line 13426 C
  perl519.dll!PerlProcFork(IPerlProc * piPerl=0x009aaf30) Line 1832 +
0x3e C

perl519.dll!Perl_pp_fork(interpreter * my_perl=) Line 4038 + 0xa C
___________________________________________________________________
IDK why the C stack cuts out after pp_fork in my debugger but this has
to be the child thread since there is only 1 thread that can execute
main() in the process.

If I look at the blocked critical section struct in child thread, the
OwningThread member is 5980, which is the parent thread.

The OS handle in the parent thread (the one on a blocking read()), is of
type "\Device\Afd\Endpoint", Afd is the Win32 kernel socket driver, so
this is socket handle.

I'm not familiar with stdio, but I'm not sure how the script got this
far. I dont think AF_UNIX is supported on Win32, so IDK if its Perl
emulation is allowing AF_UNIX to work or lack of error checking in this
script.

There is a whole group of these I've diagnosed in the past, I think that
someone else will *probably* say that out the PERL_IMPLICIT_SYS
subsystem doesn't emulate/map/catch CRT handles, so this is a case of 2
different psuedo processes using the same CRT fh and the emulation
breaks down.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2013

From @bulk88

fork_from_manual.pl

@p5pRT
Copy link
Author

p5pRT commented Jul 23, 2013

From @craigberry

On Mon, Jul 22, 2013 at 5​:18 PM, bulk88 via RT
<perlbug-followup@​perl.org> wrote​:

I'm not familiar with stdio, but I'm not sure how the script got this
far. I dont think AF_UNIX is supported on Win32, so IDK if its Perl
emulation is allowing AF_UNIX to work or lack of error checking in this
script.

Thanks for the confirmation and diagnosis. FWIW, what it's doing is
not stdio but Unix I/O (read/write rather than fread/fwrite). I
believe Windows is using the socketpair emulation in util.c, which
uses AF_INET even if you pass in AF_UNIX, so the absence of AF_UNIX is
unlikely to be part of the problem. The fact that both fork and
socketpair are being emulated could be part of the problem, but it
also might lead to a possible solution for someone who knows enough
details about how they work.

@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2015

From @bulk88

wild instance of this https://rt.cpan.org/Public/Bug/Display.html?id=81993

--
bulk88 ~ bulk88 at hotmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants