[PATCH][analyzer] Prevent ccc/c++-analyzer from hanging on Windows.
Anton Yartsev
anton.yartsev at gmail.com
Wed Nov 26 15:27:03 PST 2014
Ping!
Attached are an updated patch for ccc-analyzer and a similar patch for
scan-build, please review.
> On 06.11.2014 20:27, Jordan Rose wrote:
>> I think my point was "why bother forking at all if we're using open
>> to run a subprocess?".
> Ah, got it! Attached is an updated patch.
>
>>
>> Also, this will fail if the path contains spaces:
> Corrected.
>
>>
>> + my $ExecLine = join(' ', $Clang, "-###", $mode, @$Args, "2>&1",
>> "|");
>> + open(PS, $ExecLine);
>>
>> Do newer Perls on newer Windows support the list form of open?
> No, at least ActivePerl, StrawberryPerl and Dwimperl.
>
> Current perl docs state:
> 'open to ||-| and |-|| are unsupported. (Win32, RISC OS)'
> (http://perldoc.perl.org/perlport.html#open)
> and
> 'The open(FOO, "|-") and open(BAR, "-|") constructs are not yet
> implemented.' (http://perldoc.perl.org/perlfork.html)
>
>> Jordan
>>
>>
>>> On Nov 5, 2014, at 11:54 , Anton Yartsev <anton.yartsev at gmail.com
>>> <mailto:anton.yartsev at gmail.com>> wrote:
>>>
>>> Ping!
>>>> It seems that fork is the only native perl mean for creating
>>>> subprocesses. There is a number of packages that provide means for
>>>> spawning at cpan.org <http://cpan.org>, but they are not guarantee
>>>> to be included at the users perl distribution.
>>>>> Looking at this code, it's weird that we're doing this as a
>>>>> fork/exec (or not-exec) at all. Why can't we just spawn a sub-process?
>>>>>
>>>>> Jordan
>>>>>
>>>>>
>>>>> On Oct 21, 2014, at 6:47 , Anton Yartsev <anton.yartsev at gmail.com
>>>>> <mailto:anton.yartsev at gmail.com>> wrote:
>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> Attached is the patch that prevents ccc/c++-analyzer from hang if
>>>>>> launched with ActivePerl or Strawberry Perl interpreters.
>>>>>> The patch replaces the code that creates a pipe from child to
>>>>>> parent to the more portable explicit writing to parent, this
>>>>>> prevent interpreters from hang.
>>>>>> The conditions for hang are: child should open a pipe to the
>>>>>> parent and parent should read from the child, otherwise no hang.
>>>>>>
>>>>>> The problem is possibly caused by the bug in emulation of 'fork'
>>>>>> by Perl interpreters on Windows. From perlfork
>>>>>> <http://perldoc.perl.org/perlfork.html> documentation, BUGS section:
>>>>>> "In certain cases, the OS-level handles created by the pipe(),
>>>>>> socket(), and accept() operators are apparently not duplicated
>>>>>> accurately in pseudo-processes. This only happens in some
>>>>>> situations, but where it does happen, it may result in deadlocks
>>>>>> between the read and write ends of pipe handles, or inability to
>>>>>> send or receive data across socket handles."
>>>>>>
>>>>>> An example from perlfork documentation also hangs:
>>>>>>
>>>>>> # 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\n";
>>>>>> exit(0);
>>>>>> }
>>>>>>
>>>>>> The hang is not reproduced only with the MSYS Perl.
>>>>>>
>>>>>> OK to commit?
>>>>>> --
>>>>>> Anton
>>>>>> <ccc-analyzer_fork_open_hang.patch>
>>>>>
>>>>
>>>>
>>>> --
>>>> Anton
>>>
>>>
>>> --
>>> Anton
>>
>
>
> --
> Anton
--
Anton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141127/43d14798/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ccc-analyzer_fork_open_hang_v2.patch
Type: text/x-diff
Size: 2022 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141127/43d14798/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scan-build_fork_open_hang.patch
Type: text/x-diff
Size: 2174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141127/43d14798/attachment-0001.patch>
More information about the cfe-commits
mailing list