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

Win32 pipe/fork or filehandle I/O deadlock bug #6704

Open
p5pRT opened this issue Aug 15, 2003 · 6 comments
Open

Win32 pipe/fork or filehandle I/O deadlock bug #6704

p5pRT opened this issue Aug 15, 2003 · 6 comments
Labels
distro-mswin32 type-core type-ithreads type-portability Win32 This is a meta-ticket to tag issues in the perl core which need attention on Win32. See #11925

Comments

@p5pRT
Copy link

p5pRT commented Aug 15, 2003

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

Searchable as RT23331$

@p5pRT
Copy link
Author

p5pRT commented Aug 15, 2003

From Sean.Hunter@gs.com

Created by sean.hunter@gs.com

This is a bug report for perl from sean.hunter@​gs.com,
generated with the help of perlbug 1.33 running under perl v5.6.1.

To​: perlbug@​perl.org
Subject​: Win32 pipe/fork bug
Cc​: ficcs-installmeister@​ny.email.gs.com
Reply-To​: ficcs-installmeister@​ny.email.gs.com
Message-Id​: <5.8.0_536_1060965069@​jeeves.fi.gs.com>

This is a bug report for perl from ficcs-installmeister@​ny.email.gs.com,
generated with the help of perlbug 1.34 running under perl v5.8.0.

-----------------------------------------------------------------

Hi there

The following code, (copied directly from perlfork.pod) deadlocks on Win32 (XP
and NT4) under 5.8.0. 5.6.1 on Win32 and 5.8.0 on Solaris and Linux work fine
for me. I have tried the same code with a build without PERLIO and the
standard ActiveState perl 5.8.0. The AS perl deadlocks and sits there until
interrupted. The build without PERLIO exits without printing the message. I
have tried various settings of the PERLIO environment variable without any
noticable effect.

FWIW I see the same behaviour with tcp sockets between the parent and child
processes.

Cheers

Sean

# simulate open(FOO, "-|")
sub pipe_from_fork ($) {
my $parent = shift;
pipe $parent, my $child or die;
my $pid = fork();
die "fork() failed: $!" unless defined $pid;
if ($pid) {
close $child;
}
else {
close $parent;
open(STDOUT, ">&=" . fileno($child)) or die;
}
$pid;
}

if (pipe_from_fork('BAR')) {
# parent
while (<BAR>) { print; }
close BAR;
}
else {
# child
print "pipe_from_fork certified \"100% Probably Working [tm]\"! Have a nice day.\n";
close STDOUT;
exit(0);
}
Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl v5.8.0:

Configured by huntse at Wed Jun 18 18:43:25 2003.

Summary of my perl5 (revision 5 version 8 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=undef usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -Gf -W3 -MD -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT   -DDEBUGGING -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release  -libpath:"I:\sw\external\perl-5.8.0\lib\CORE"  -machine:x86'
    libpth=C:\local\apps\GS\Micros~3\VC98\lib I:\sw\external\utils\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release  -libpath:"I:\sw\external\perl-5.8.0\lib\CORE"  -machine:x86'

Locally applied patches:
    


@INC for perl v5.8.0:
    i:/sw/external/perl-5.8.0/lib
    i:/sw/external/perl-5.8.0/site/lib
    .


Environment for perl v5.8.0:
    HOME=z:\
    LANG (unset)
    LANGUAGE=_XP
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=i:\sw\external\perl-5.8.0\bin\;C:\PROGRA~1\Micros~3\VC98\bin;C:\PROGRA~1\Micros~3\Common\msdev98\bin;i:\sw\external\cygwin-1.3.20-GS\bin;i:\sw\external\utils\bin;I:\sw\ficc\wraps\bin;I:\ja\prod\offtrain\dllw32;I:\ja\prod\offtrain\utilw32;I:\ja\prod\dllw32;I:\ja\prod\utilw32;I:\sw\external\jdk-1.3\bin;I:\sw\external\jdk-1.3\jre\bin\hotspot;I:\sw\external\ACE-5.2\bin;C:\Progra~1\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Support Tools\;C:\Program Files\SQLLIB\BIN;C:\Program Files\SQLLIB\HELP;c:\Program Files\RV\BIN;c:\Program Files\sybase\OCS-12_0\dll\;c:\Program Files\sybase\OCS-12_0\bin;c:\Program Files\sybase\asep;c:\Program Files\sybase\sqlremote\dll;%C:\WINDOWS%\system32;%C:\WINDOWS%;%C:\WINDOWS%\System32\Wbem;c:\Program Files\Hummingbird\Connectivity\8.00\Accessories\;;I:\sw\ficc\wraps\bin;Z:\xp\cmd;Z:\cmd;I:\sw\ficc\links\bin;I:\sw\external\links\bin;I:\sw\external\utils\bin;I:\ja\prod\offtrain\dllw32;I:\ja\prod\offtrain\u
 tilw32;I:\ja\prod\dllw32;I:\ja\prod\utilw32;I:\mksv51\mksnt;I:\sw\external\Roguewave-7.1.1\NT40_VC60\lib;I:\sw\external\mkl-rw7.1.1\bin;I:\gnu\bin;I:\vslick\win;I:\msvc60_dbug;I:\Util;I:\DLL;I:\sw\external\og-6.0\bin;I:\sw\external\ACE-5.2\bin;
    PERLIO=perlio
    PERL_BADLANG (unset)
    PERL_PATH=I:\ja\prod\utilw32
    SHELL (unset)


@p5pRT
Copy link
Author

p5pRT commented Apr 14, 2004

From perlbug@ericgarland.com

I've hit this issue as well.

From what I can tell something broke in the fork emulation on Win32 in
5.8. Here is a really simple example script that demonstrates the
problem. It forks, has the child redirect STDOUT to a file, then prints
in the parent. The parent's output shouldn't be redirected but it is.

if ($pid=fork() ) {
  sleep(1);
  print "parent\n";
} else {
  open (STDOUT, ">test.txt");
  system("echo child");
}

The really nasty effect of this bug is that things appear to work fine
in the parent until the child redirects STDOUT. The parrent will seem
to be functioning properly and then stop working at some later
(seemingly random) time when the child does something with it's filehandle.

It appears that the filehandles aren't getting dup'd anymore when the
fork emulation happens like it used to in 5.6. I have tested with 5.8.2
and 5.8.3 on two different machines running different versions of
Windows (2000 and XP Home). It happened everywhere.

Does anyone know if the filehandle dup'ing code changed between 5.6 and 5.8?

Thanks

  -Eric

@p5pRT
Copy link
Author

p5pRT commented Aug 14, 2012

From @jkeenan

This ticket has languished for many years. Could someone on Win32
(version supported by vendor) and recent version of Perl (5.14 or 5.16
or their ActivePerl equivlents) give this a spin?

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 Aug 14, 2012

From @bulk88

Created attached file. Ran with VC Perl 5.17, DEBUGGING. result = hung,
C callstack is
______________________________________________
ntdll.dll!_KiFastSystemCallRet@0()
ntdll.dll!_ZwWriteFile@36() + 0xc
kernel32.dll!_WriteFile@20() + 0x6f
> msvcr71.dll!_write_lk(int fh=0x008f29c8, const void * buf=0x0012f854,
unsigned int cnt=0x28205392) Line 198 + 0x14 C
msvcr71.dll!_write(int fh=0x00000001, const void * buf=0x0092ca04,
unsigned int cnt=0x00000201) Line 79 + 0xc C
perl517.dll!win32_write(int fd=0x00000001, const void *
buf=0x0092ca04, unsigned int cnt=0x00000201) Line 3213 + 0x12 C
perl517.dll!PerlLIOWrite(IPerlLIO * piPerl=0x0034684c, int
handle=0x00000001, const void * buffer=0x0092ca04, unsigned int
count=0x00000201) Line 1081 + 0x11 C++
perl517.dll!PerlIOUnix_write(interpreter * my_perl=0x00384234, _PerlIO
* * f=0x008f28e4, const void * vbuf=0x0092ca04, unsigned int
count=0x00000201) Line 2822 + 0x22 C
perl517.dll!Perl_PerlIO_write(interpreter * my_perl=0x00384234,
_PerlIO * * f=0x008f28e4, const void * vbuf=0x0092ca04, unsigned int
count=0x00000201) Line 1695 + 0x3e C
perl517.dll!PerlIOBuf_flush(interpreter * my_perl=0x00384234, _PerlIO
* * f=0x008f23fc) Line 3931 + 0x1b C
perl517.dll!PerlIOCrlf_flush(interpreter * my_perl=0x00384234, _PerlIO
* * f=0x008f23fc) Line 4767 + 0xd C
perl517.dll!Perl_PerlIO_flush(interpreter * my_perl=0x00384234,
_PerlIO * * f=0x008f23fc) Line 1719 + 0xe C
perl517.dll!PerlIOCrlf_write(interpreter * my_perl=0x00384234, _PerlIO
* * f=0x008f23fc, const void * vbuf=0x00917024, unsigned int
count=0x00000200) Line 4739 + 0xd C
perl517.dll!Perl_PerlIO_write(interpreter * my_perl=0x00384234,
_PerlIO * * f=0x008f23fc, const void * vbuf=0x00917024, unsigned int
count=0x00000200) Line 1695 + 0x3e C
perl517.dll!Perl_do_print(interpreter * my_perl=0x00384234, sv *
sv=0x00386d7c, _PerlIO * * fp=0x008f23fc) Line 1267 + 0x1b C
perl517.dll!Perl_pp_print(interpreter * my_perl=0x00384234) Line
731 + 0x13 C
perl517.dll!Perl_runops_debug(interpreter * my_perl=0x00384234) Line
2129 + 0xd C
perl517.dll!S_run_body(interpreter * my_perl=0x00384234, long
oldscope=0x00000001) Line 2387 + 0xd C
perl517.dll!perl_run(interpreter * my_perl=0x00384234) Line 2304 + 0xd C
perl517.dll!RunPerl(int argc=0x00000002, char * * argv=0x00342cc8,
char * * env=0x003459c8) Line 270 + 0x9 C++
perl.exe!mainCRTStartup() Line 398 + 0xe C
kernel32.dll!_BaseProcessStart@4() + 0x23
_______________________________________________
curcop file is "pipe1.pl", curcop line is 18.
Buffer to CRT write() is
__________________________________________________
0x0092CA04 70 69 70 65 5f 66 72 6f 6d 5f 66 6f 72 6b 20 63 65 72 74 69
66 69 65 64 20 22 31 30 30 pipe_from_fork certified "100
0x0092CA21 25 20 50 72 6f 62 61 62 6c 79 20 57 6f 72 6b 69 6e 67 20 5b
74 6d 5d 22 21 20 48 61 76 % Probably Working [tm]"! Hav
0x0092CA3E 65 20 61 20 6e 69 63 65 20 64 61 79 2e 0d 0d 0d 0d 0d 0d 0d
0d 0d 0d 0d 0d 0d 0d 0d 0d e a nice day.................
__________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Aug 14, 2012

From @bulk88

sub pipe_from_fork ($) {
    my $parent = shift;
    pipe $parent, my $child or die;
    my $pid = fork();
    die "fork() failed: $!" unless defined $pid;
    if ($pid) {
        close $child;
    }
    else {
    close $parent;
    open(STDOUT, ">&=" . fileno($child)) or die;
    }
    $pid;
}

if (pipe_from_fork('BAR')) {
    # parent
    while (<BAR>) { print; }
    close BAR;
}
else {
    # child
    print "pipe_from_fork certified \"100% Probably Working [tm]\"! Have a nice day.\n";
    close STDOUT;
    exit(0);
}

@toddr toddr added the Win32 This is a meta-ticket to tag issues in the perl core which need attention on Win32. See #11925 label Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distro-mswin32 type-core type-ithreads type-portability Win32 This is a meta-ticket to tag issues in the perl core which need attention on Win32. See #11925
Projects
None yet
Development

No branches or pull requests

3 participants