<div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 5, 2018 at 5:01 AM Raphael Isemann via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">@Jonas: Did you confirm it is SIGHUP? I remember that we were not sure<br>
whether the signal kind was SIGHUP or SIGINT.<br></blockquote><div><br></div><div>I'm relatively sure. I added a signal handler to lit and it fires on the signal.  </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
- Raphael<br>
Am Mi., 5. Dez. 2018 um 10:25 Uhr schrieb Pavel Labath via lldb-dev<br>
<<a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a>>:<br>
><br>
> On 05/12/2018 03:49, Jonas Devlieghere via lldb-dev wrote:<br>
> > Hi everyone,<br>
> ><br>
> > Since we switched to lit as the test driver we've been seeing it getting killed as the result of a SIGHUP signal. The problem doesn't reproduce on every machine and there seems to be a correlation between number of occurrences and thread count.<br>
> ><br>
> > Davide and Raphael spent some time narrowing down what particular test is causing this and it seems that TestChangeProcessGroup.py is always involved. However it never reproduces when running just this test. I was able to reproduce pretty consistently with the following filter:<br>
> ><br>
> > ./bin/llvm-lit ../llvm/tools/lldb/lit/Suite/ --filter="process"<br>
> ><br>
> > Bisecting the test itself didn't help much, the problem reproduces as soon as we attach to the inferior.<br>
> ><br>
> > At this point it is still not clear who is sending the SIGHUP and why it's reaching the lit test driver. Fred suggested that it might have something to do with process groups (which would be an interesting coincidence given the previously mentioned test) and he suggested having the test run in different process groups. Indeed, adding a call to os.setpgrp() in lit's executeCommand and having a different process group per test prevent us from seeing this. Regardless of this issue I think it's reasonable to have tests run in their process group, so if nobody objects I propose adding this to lit in llvm.<br>
> ><br>
> > Still, I'd like to understand where the signal is coming from and fix the root cause in addition to the symptom. Maybe someone here has an idea of what might be going on?<br>
> ><br>
> > Thanks,<br>
> > Jonas<br>
> ><br>
> > PS<br>
> ><br>
> > 1. There's two places where we send a SIGHUP ourself, with that code removed we still receive the signal, which suggests that it might be coming from Python or the OS.<br>
> > 2. If you're able to reproduce you'll see that adding an early return before the attach in TestChangeProcessGroup.py hides/prevents the problem. Moving the return down one line and it pops up again.<br>
> > _______________________________________________<br>
> > lldb-dev mailing list<br>
> > <a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a><br>
> > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
> ><br>
><br>
> Hi Jonas,<br>
><br>
> Sounds like you have found an interesting issue to debug. I've tried<br>
> running the command you mention locally, and I didn't see any failures<br>
> in 100 runs.</blockquote><div><br></div><div>Thank you. This confirm my suspicion that it's likely a Darwin-only thing.</div><div>  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
> There doesn't seem to be anything in the TestChangeProcessGroup which<br>
> sends a signal, though I can imagine that the act of changing a process<br>
> group mid-debug could be enough to confuse someone to send it. However,<br>
> I am having trouble reconciling this with your PS #2, because if<br>
> attaching is sufficient to trigger this (i.e., no group changing takes<br>
> place), then this test is not much different than any other test where<br>
> we spawn an inferior and then attach to it.<br></blockquote><div><br></div><div>I agree, I think it might be just coincidence. Also running only this test never fails so there is some timing involved. It looks like we needed at least one other process-manipulating test to make it reproduce, but this is just observation on my part and hard to confirm. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
> I am aware of one other instance where we send a spurious signal, though<br>
> it's SIGINT in this case<br>
> <<a href="https://github.com/llvm-mirror/lldb/blob/master/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp#L3645" rel="noreferrer" target="_blank">https://github.com/llvm-mirror/lldb/blob/master/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp#L3645</a>>.<br>
> The issue there is that we don't check whether the debug server has<br>
> exited before we send SIGINT to it (which it normally does on its own at<br>
> the end of debug session). So if the debug server does exit and its pid<br>
> gets recycled before we get a chance to send this signal, we can end up<br>
> killing a random process.<br></blockquote><div><br></div><div>I believe that posix doesn't make this guarantee, but that in reality neither linux nor darwin recycles pids before they wrap around? I don't see this signal in my DTrace output though. What I do see is that debugserver sends a SIGSTOP (13) to the inferior. I was entertaining the idea that maybe lldb crashes, debugserver notices that the socket is closed and tries to stop the inferior before killing it. We run the inferior with "shell=True" so if that somehow causes the shell to crash it might send a signal to the whole group. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
> Now this may seem unrelated to your issue, but SIGHUP is sent<br>
> automatically as a result of a process losing its controlling tty. So,<br>
> if that SIGINT ends up killing the process holding the master end of a<br>
> pty, this could result in some SIGHUPs being sent too. Unfortunately,<br>
> this doesn't fully stack up either, because the process holding the<br>
> master pty is probably a long-lived one, so its pid is unlikely to match<br>
> one of the transient debugserver pids. Nevertheless, it could be worth<br>
> just commenting out that line and seeing what happens.<br>
><br>
> For debugging, maybe you could try installing a SIGHUP handler into the<br>
> lit process, which would dump the received siginfo_t structure. Decoding<br>
> that may provide some insight into who is sending that signal (si_pid)<br>
> and why (si_code).<br></blockquote><div><br></div><div>This doesn't seem to be available in Python 2 so I'm trying to write my own module and loading that. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
> As for adding process group support into lit, I think that having each<br>
> test run (*not* each executed command) in it's own group is reasonable.<br>
> However, be aware that this changes the behaviour of how all signals (in<br>
> particular the SIGINT you get when typing ^C) get delivered. AFAIK, lit<br>
> doesn't have any special code for cleaning up the spawned processes and<br>
> relies on the fact that ^C will send a SIGINT to the entire "foreground<br>
> process group" and terminate stuff. If you start creating a bunch of<br>
> process groups, you may need to add more explicit termination logic too.<br></blockquote><div><br></div><div>Good point, being able to ^C was a big part of the reason I wanted to switch to lit in the first place so this is the last thing I want to break ;-)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
> cheers,<br>
> pl<br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
_______________________________________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
</blockquote></div></div></div>