develooper Front page | perl.perl5.porters | Postings from March 2014

[perl #38723] Backticks don't work in Win32 multithreaded perl

Thread Previous | Thread Next
From:
bulk88 via RT
Date:
March 24, 2014 07:15
Subject:
[perl #38723] Backticks don't work in Win32 multithreaded perl
Message ID:
rt-4.0.18-5004-1395645340-492.38723-15-0@perl.org
On Sun Mar 23 22:16:54 2014, tonyc wrote:
> On Sun Mar 23 21:40:25 2014, tonyc wrote:
> > It's possible I've fixed this in
> > f06c882585eac59ec68dbf93c87659cb62a24000 which avoids modifying the
> > global stdin/out handles when creating a popen() process.
> 
> I tested with 64-bit 5.18.1 and blead@v5.19.8-291-ga27b5f5*.
> 
> Neither locked up, but 5.18.1 did drop a lot of output.
> 
> blead produced a lot more output and appears to have output a line for
> each iteration of the "child processes".
> 
> I'll close this soon unless someone objects.
> 
> Tony

I got AP 5.10 to hang, it takes 3-8 trys before it hangs with a slightly tweaked script.

------------------------------------------
sub run_p($)
{
	my($num) = @_;
	print "Process $num($$) started.\n";
	for(1..20){
		`dir`;
		print "Process $num iteration $_\n";
	}
	print LOG "Process $num done.\n";
}

$|=1;
my $NFORK=20;
open LOG,">log.txt";
for(1..$NFORK){
	my $pid;
	if(($pid=fork())){
		#print "Starting process $_($pid)\n";
		$num{$pid} = $_;
	}
	else{
		sleep 1;
		run_p($_);
		exit;
	}
}
for(1..$NFORK){
	my $pid= wait();
	print STDERR "Wait returned $pid ($num{$pid})\n";
}
-------------------------------------------------------

---------------------------------
 	ntdll.dll!_KiFastSystemCallRet@0() 	
 	ntdll.dll!_ZwWaitForMultipleObjects@20()  + 0xc	
 	kernel32.dll!_WaitForMultipleObjectsEx@20()  - 0x48	
 	user32.dll!_RealMsgWaitForMultipleObjectsEx@20()  + 0xd9	
 	user32.dll!_MsgWaitForMultipleObjects@20()  + 0x1f	
 	perl510.dll!win32_msgwait(interpreter * my_perl=0x00234164, unsigned long count=20, void * * handles=0x0023f4a0, unsigned long timeout=4294967295, unsigned long * resultp=0x0140fa74)  Line 2160 + 0x15	C
 	perl510.dll!win32_internal_wait(int * status=0x0140fafc, unsigned long timeout=4294967295)  Line 2202	C
 	perl510.dll!win32_waitpid(int pid=-1, int * status=0x0140fafc, int flags=0)  Line 2259 + 0x9	C
	perl510.dll!PerlProcWaitpid(IPerlProc * piPerl=0x00235a98, int pid=-1, int * status=0x0140fafc, int flags=0)  Line 1690 + 0x11	C++
 	perl510.dll!Perl_wait4pid(interpreter * my_perl=0x00234164, int pid=-1, int * statusp=0x0140fafc, int flags=0)  Line 2925 + 0x17	C
 	perl510.dll!Perl_pp_wait(interpreter * my_perl=0x00234164)  Line 4010 + 0xa	C
 	perl510.dll!Perl_runops_standard(interpreter * my_perl=0x00234164)  Line 36 + 0xc	C
 	perl510.dll!S_run_body(interpreter * my_perl=0x00234164, long oldscope=1)  Line 2385 + 0x7	C
 	perl510.dll!perl_run(interpreter * my_perl=0x00234164)  Line 2303 + 0xa	C
 	perl510.dll!RunPerl(int argc=2, char * * argv=0x00233f08, char * * env=0x01232d08)  Line 266 + 0x6	C++
 	perl.exe!main(int argc=2, char * * argv=0x00233f08, char * * env=0x00232d08)  Line 22 + 0x12	C
 	perl.exe!_mainCRTStartup()  + 0xe3	
 	kernel32.dll!_BaseProcessStart@4()  + 0x23	
-----------------------
 	ntdll.dll!_RtlpWaitForCriticalSection@4()  + 0x8c	
 	ntdll.dll!_RtlEnterCriticalSection@4()  + 0x46	
 	msvcrt.dll!__lock_fhandle()  + 0x70	
 	msvcrt.dll!__write()  + 0x3d	
 	perl510.dll!win32_write(int fd=1, const void * buf=0x07ae0a04, unsigned int cnt=23)  Line 3701 + 0x12	C
	perl510.dll!PerlLIOWrite(IPerlLIO * piPerl=0x01830cd4, int handle=1, const void * buffer=0x07ae0a04, unsigned int count=23)  Line 1094 + 0x11	C++
 	perl510.dll!PerlIOUnix_write(interpreter * my_perl=0x01834f2c, _PerlIO * * f=0x0183e35c, const void * vbuf=0x07ae0a04, unsigned int count=23)  Line 2711 + 0x1a	C
 	perl510.dll!Perl_PerlIO_write(interpreter * my_perl=0x01834f2c, _PerlIO * * f=0x0183e35c, const void * vbuf=0x07ae0a04, unsigned int count=23)  Line 1643 + 0x2b	C
 	perl510.dll!PerlIOBuf_flush(interpreter * my_perl=0x01834f2c, _PerlIO * * f=0x07ae0a04)  Line 3748 + 0x10	C
 	perl510.dll!PerlIOCrlf_flush(interpreter * my_perl=0x01834f2c, _PerlIO * * f=0x0183e1b4)  Line 4585 + 0xa	C
 	perl510.dll!Perl_PerlIO_flush(interpreter * my_perl=0x01834f2c, _PerlIO * * f=0x0183e1b4)  Line 1668 + 0x6	C
 	perl510.dll!PerlIOCrlf_write(interpreter * my_perl=0x01834f2c, _PerlIO * * f=0x0183e1b4, const void * vbuf=0x07aed4f4, unsigned int count=128898314)  Line 4566 + 0x9	C
 	perl510.dll!Perl_PerlIO_write(interpreter * my_perl=0x01834f2c, _PerlIO * * f=0x0183e1b4, const void * vbuf=0x07aed4f4, unsigned int count=22)  Line 1643 + 0x2b	C
 	perl510.dll!Perl_do_print(interpreter * my_perl=0x01834f2c, sv * sv=0x0183ba94, _PerlIO * * fp=0x0183e1b4)  Line 1247 + 0x13	C
 	perl510.dll!Perl_pp_print(interpreter * my_perl=0x018549d0)  Line 778 + 0xb	C
 	perl510.dll!Perl_runops_standard(interpreter * my_perl=0x01834f2c)  Line 36 + 0xc	C
 	perl510.dll!win32_start_child(void * arg=0x01834f2c)  Line 1769 + 0x7	C++
 	kernel32.dll!_BaseThreadStart@8()  + 0x37	
---------------------------------------------------
 	ntdll.dll!_KiFastSystemCallRet@0() 	
 	ntdll.dll!_ZwWaitForSingleObject@12()  + 0xc	
 	ntdll.dll!_RtlpWaitForCriticalSection@4()  + 0x8c	
 	ntdll.dll!_RtlEnterCriticalSection@4()  + 0x46	
 	msvcrt.dll!__lock_fhandle()  + 0x70	
 	msvcrt.dll!__dup2()  + 0x74	
 	perl510.dll!win32_dup2(int fd1=6, int fd2=1)  Line 3489 + 0xe	C
 	perl510.dll!win32_popen(const char * command=0x00001f4c, const char * mode=0x280b3b1c)  Line 3055 + 0xb	C
	perl510.dll!PerlProcPopen(IPerlProc * piPerl=0x01851d70, const char * command=0x0186825c, const char * mode=0x280b3b1c)  Line 1635 + 0xd	C++
 	perl510.dll!Perl_pp_backtick(interpreter * my_perl=0x0186825c)  Line 316 + 0xe	C
 	perl510.dll!Perl_runops_standard(interpreter * my_perl=0x01852914)  Line 36 + 0xc	C
 	perl510.dll!win32_start_child(void * arg=0x01852914)  Line 1769 + 0x7	C++
 	kernel32.dll!_BaseThreadStart@8()  + 0x37	
---------------------------------------------------------------------

ll child threads with this identical call stack

---------------------------------------------------------------------
 	ntdll.dll!_KiFastSystemCallRet@0() 	
 	ntdll.dll!_ZwWaitForSingleObject@12()  + 0xc	
 	ntdll.dll!_RtlpWaitForCriticalSection@4()  + 0x8c	
 	ntdll.dll!_RtlEnterCriticalSection@4()  + 0x46	
 	perl510.dll!win32_popen(const char * command=0x0188a1cc, const char * mode=0x280b3b1c)  Line 3031	C
	perl510.dll!PerlProcPopen(IPerlProc * piPerl=0x0187a8e8, const char * command=0x0188a1cc, const char * mode=0x280b3b1c)  Line 1635 + 0xd	C++
 	perl510.dll!Perl_pp_backtick(interpreter * my_perl=0x0188a1cc)  Line 316 + 0xe	C
 	perl510.dll!Perl_runops_standard(interpreter * my_perl=0x01873694)  Line 36 + 0xc	C
 	perl510.dll!win32_start_child(void * arg=0x01873694)  Line 1769 + 0x7	C++
 	kernel32.dll!_BaseThreadStart@8()  + 0x37	
--------------------------------------------------------------------

7 child threads with this call stack

--------------------------------------------------------------------
 	ntdll.dll!_KiFastSystemCallRet@0() 	
 	ntdll.dll!_ZwWaitForSingleObject@12()  + 0xc	
 	ntdll.dll!_RtlpWaitForCriticalSection@4()  + 0x8c	
 	ntdll.dll!_RtlEnterCriticalSection@4()  + 0x46	
 	msvcrt.dll!__lock_fhandle()  + 0x70	
 	msvcrt.dll!__write()  + 0x3d	
 	perl510.dll!win32_write(int fd=1, const void * buf=0x07aef88c, unsigned int cnt=24)  Line 3701 + 0x12	C
	perl510.dll!PerlLIOWrite(IPerlLIO * piPerl=0x079e9d4c, int handle=1, const void * buffer=0x07aef88c, unsigned int count=24)  Line 1094 + 0x11	C++
 	perl510.dll!PerlIOUnix_write(interpreter * my_perl=0x079eaa14, _PerlIO * * f=0x079f7b24, const void * vbuf=0x07aef88c, unsigned int count=24)  Line 2711 + 0x1a	C
 	perl510.dll!Perl_PerlIO_write(interpreter * my_perl=0x079eaa14, _PerlIO * * f=0x079f7b24, const void * vbuf=0x07aef88c, unsigned int count=24)  Line 1643 + 0x2b	C
 	perl510.dll!PerlIOBuf_flush(interpreter * my_perl=0x079eaa14, _PerlIO * * f=0x07aef88c)  Line 3748 + 0x10	C
 	perl510.dll!PerlIOCrlf_flush(interpreter * my_perl=0x079eaa14, _PerlIO * * f=0x079f797c)  Line 4585 + 0xa	C
 	perl510.dll!Perl_PerlIO_flush(interpreter * my_perl=0x079eaa14, _PerlIO * * f=0x079f797c)  Line 1668 + 0x6	C
 	perl510.dll!PerlIOCrlf_write(interpreter * my_perl=0x079eaa14, _PerlIO * * f=0x079f797c, const void * vbuf=0x07afc4cc, unsigned int count=128959715)  Line 4566 + 0x9	C
 	perl510.dll!Perl_PerlIO_write(interpreter * my_perl=0x079eaa14, _PerlIO * * f=0x079f797c, const void * vbuf=0x07afc4cc, unsigned int count=23)  Line 1643 + 0x2b	C
 	perl510.dll!Perl_do_print(interpreter * my_perl=0x079eaa14, sv * sv=0x019f52a4, _PerlIO * * fp=0x079f797c)  Line 1247 + 0x13	C
 	perl510.dll!Perl_pp_print(interpreter * my_perl=0x07a10950)  Line 778 + 0xb	C
 	perl510.dll!Perl_runops_standard(interpreter * my_perl=0x079eaa14)  Line 36 + 0xc	C
 	perl510.dll!win32_start_child(void * arg=0x079eaa14)  Line 1769 + 0x7	C++
 	kernel32.dll!_BaseThreadStart@8()  + 0x37	
-------------------------------------------------------------

The perl OS process has a blocked cmd.exe child proc under it launched as "cmd.exe /x/d/c dir". IDK which perl fork thread is supposed to be reading from the cmd.exe process. I won't debug this very throughly but I'll look at it in another post, because, doing a perl -E" for(0..200){system('perl winhang.pl');}" with blead at http://perl5.git.perl.org/perl.git/commit/e9251c1a8f4944e6dceff5240d9e109ba075ff29 never hanged for me. 

-- 
bulk88 ~ bulk88 at hotmail.com

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

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