-
Notifications
You must be signed in to change notification settings - Fork 25
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
arm64 builds hangs on install-info a lot #62
Comments
I believe this is a bug in cygwin/msys2-runtime, because it also happened with pacman frequently when it would verify sync db signatures. The workaround I had for that was to append |
Add attempted workaround for install-info.exe hanging, by disabling the pacman hooks that call it. msys2/msys2-autobuild#62
I wonder whether this is still the case for v3.4.*... |
This hang seems to be happening much more often with the new 2023 dev kit machine compared to the qc710. It is now even happening when validating signatures on packages, where it would usually only happen validating database signatures before. |
Me and the GIMP project have also seen this. There's a comment lost in a Merge Request (Gitlab) somewhere about it. They decided to stop pacman update as part of the builds and the runners are now doing this on a daily scheduled task with timeout/retry overnight :( |
I gathered some information that may be helpful for analyzing this issue, and wrote it down here. |
I wonder if it might possibly be https://cygwin.com/pipermail/cygwin/2024-February/255431.html. Maybe we can try backporting that patch (msys2/msys2-runtime@4e77fa9b8bf4) and see if the issues go away? |
If anyone else wants to try, I built msys2-runtime and msys2-runtime-3.3 with that patch applied in https://github.com/jeremyd2019/MSYS2-packages/actions/runs/7921543265. I am planning to try some things with it and see what happens. UPDATE: that seems pretty broken. I'm guessing I didn't backport the fix correctly. |
https://github.com/jeremyd2019/MSYS2-packages/actions/runs/7924206550 is at least not as immediately broken 😉. Will test that |
I built both 3.4 and 3.3, and 3.3 for 32-bit (which took some doing because any binutils later than 2.40 resulted in a broken msys-2.0.dll). I then set both a Windows 11 VM on the Dev Kit and a Windows 10 install on a Raspberry Pi 4 in a loop running pacman (without disabling db signature checking). The raspberry pi did hang up, but the debugger looks different than I remember. The dev kit vm is still going at last check. |
I think the 32-bit on the raspberry pi hung up in |
Looking back at the cygwin thread, it seems that patch was introduced after a report of a hang with 100% CPU usage, rather than the hang with 0 CPU usage that we see, so I'm not sure it's the same issue. I guess I'll keep looking into the |
With debug build it hung up somewhere different, but doesn't make any more sense. This time it hung up apparently during process teardown, having called |
The 64-bit msys2 on windows 11 did eventually hang too |
When running `pacman` on Windows/ARM64, we frequently run into curious hangs (see msys2/msys2-autobuild#62 for more details). This commit aims to work around that by replacing the double-fork with a single-fork in `_gpgme_io_spawn()`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
I finally have some good news. While I am not even close to a fix, I have a work-around: msys2/MSYS2-packages#4583 Here is a run of Git for Windows' By manually observing the hangs (RDPing into those self-hosted runners) I figured out that there were typically around half a dozen hanging processes whose command-lines were identical to their respective parent processes' command-lines. I've tracked that down to One thing that helped me tremendously while debugging this was the insight that calling that PowerShell script that runs So these are my thoughts how to proceed from here:
|
In that case, I wonder if there's a race between starting up the wait thread and shutting it down during process exit. Assuming the second fork is followed by an exec in the (grand)child, that could further complicate things because I think that there is some magic that shuffles around the process tree to try to make it look as though exec actually replaced the process instead of starting a new one. (I think that may even be involved in the wait thread). I never did get a good understanding of locking around this code, either. This is why I was trying Interlocked operations, to see if maybe there was a race going on, because I was seeing things in the debugger like handles that were NULL in the struct, but the stack showed a non-NULL handle passed to functions like CloseHandle or TerminateThread. I think I was satisfied that they were moving the handle into a temp variable and nulling it in the struct before closing it, but it felt like it was trying to avoid a race in a not-horribly-effective manner. As for a Windows bug, I couldn't see any good reason for TerminateThread to block. I was a little concerned that maybe terminating a thread could leave the emulation in a bad state. |
I read the code, and I think I understand what it is trying to do. It has this comment: /* Intermediate child to prevent zombie processes. */ As I recall, there is a "rule" on *nix that a parent must wait on a child process (or ignore |
@jeremyd2019 I believe you’re 100% correct, and TIL: http://stackoverflow.com/questions/10932592/why-fork-twice/16655124#16655124 And I think it’s exactly the reason why it un-hangs if I manually kill the “right” pacman process (the intermediate child apparently). Which probably means that it’s actually the intermediate child that hangs (maybe because the grandchild exits too soon?). Hope this information helps in diagnosing the root cause 🤞 |
Another wrinkle is that Windows doesn't have a concept of |
Well that didn't take long: #include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#ifndef BINARY
#define BINARY "/bin/sleep"
#endif
#ifndef ARG
#define ARG "0.1"
#endif
int main(int argc, char ** argv)
{
while (1)
{
int pid;
printf("Starting group of 100x " BINARY " " ARG "\n");
for (int i = 0; i < 100; ++i)
{
pid = fork();
if (pid == -1)
{
perror("fork error");
return 1;
}
else if (pid == 0)
{
if ((pid = fork()) == 0)
{
char * const args[] = {BINARY, ARG, NULL};
execv(BINARY, args);
perror("execv failed");
_exit(5);
}
if (pid == -1)
_exit(1);
else
_exit(0);
}
else
{
int status;
if (waitpid(pid, &status, 0) == -1)
{
perror("waitpid error");
return 2;
}
else if (status != 0)
{
fprintf(stderr, "subprocess exited non-zero: %d\n", status);
return WEXITSTATUS(status);
}
}
}
}
return 0;
} built that with |
On the raspberry pi/windows 10 at least, this seems to hang pretty reliably after 11 lines, with either /bin/true or /bin/sleep (leaving 0.1 as the arg). I still can't get gdb to do anything useful, I'm thinking |
@jeremyd2019! This is fantastic news! Excellent work. How about contributing this reproducer to the Cygwin (or |
To the surprise of probably nobody, in my experiments this reproducer does not reproduce on my x86_64 machine, neither with MSYS2 nor with Cygwin. |
https://cygwin.com/pipermail/cygwin-developers/2024-May/012694.html |
When running `pacman` on Windows/ARM64, we frequently run into curious hangs (see msys2/msys2-autobuild#62 for more details). This commit aims to work around that by replacing the double-fork with a single-fork in `_gpgme_io_spawn()`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Hmm, I was looking at the cygwin/msys2-runtime code for something else, and came across this comment: Don't know, but LOL anyway |
I'm really sorry to add a noobish comment, but I have been following this with interest - as I have observed that the same behaviour seems to be exhibited when working with msys2/pacman via an x64 Windows instance during a Given the amazing digging you've done here, and the nature of working with Windows containers/ The workaround in my case is just to tell Thought I might add that in case you're looking to find a case where even |
@chadlwilson I guess one way to find out is see if the reproducer produces similar results in container? |
Yeah, fair comment. Unfortunately I don't have a super easy way to do so as don't have an x64 machine so have to do so via GHA or similar which I haven't got around to yet. |
When running `pacman` on Windows/ARM64, we frequently run into curious hangs (see msys2/msys2-autobuild#62 for more details). This commit aims to work around that by replacing the double-fork with a single-fork in `_gpgme_io_spawn()`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
When running `pacman` on Windows/ARM64, we frequently run into curious hangs (see msys2/msys2-autobuild#62 for more details). This commit aims to work around that by replacing the double-fork with a single-fork in `_gpgme_io_spawn()`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
The new 24h2 version of Windows 11 introduces a new x64 emulation engine for arm64 called Prism. I wonder if that would solve any of the hangs we've been seeing on x64-emulated processes like pacman and other tools... |
Note though that Prism isn’t really “new” but it does drop some old ARMv8.0 support code, which might indeed have had an impact I guess. Also, @dscho has mentioned before that it might have been fixed in later builds of 24H2, though it might not be related to Prism (since what’s marketed now as “Prism” presumably appeared in much earlier builds of Germanium). |
I bring bad news 😞 . My Surface Laptop Copilot+ PC arrived yesterday, and that comes with Windows 11 24H2. Today I started local dev stuff with MSYS2 and I already saw the |
Good news 🙂 you can now debug the issue yourself (if possible). |
I could before 😅. I have had a Snapdragon 8cx (Gen 1 then Gen 3) laptops since 2019. The issue is that I don't know how. If it was Visual Studio I could probably help. |
To bring my latest theory to this thread: I believe the issue happening around the tearing down of the wait thread circa https://github.com/msys2/msys2-runtime/blob/28d69fba269dd4a9f4281f8af7c2775292241e8b/winsup/cygwin/sigproc.cc#L412-L413. My latest concern I ran into is that because the |
Hi folks. I am not well versed in the inner workings of Cygwin but I do know quite well how the emulator works, so I am here to help in as much capacity as I can. I am told Cygwin does not use RtlCloneUserProcess, but I compiled and ran the test code (as well as pacman) and looked at the state of the hung child and I am seeing something that is not much different than what RtlCloneUserProcess does. The child process contains a number of threads (on of which named "sig") and they are all blocked on the emulator's code-cache lock. There is no thread in this process owning the lock. This is what creates the deadlock. As I mentioned, I don't have any insight on how Cygwin implements fork, but the result suggests that the thread owning the emulator lock hasn't (yet?) been migrated over and, without it, nothing can make forward progress in emulation. This also explains the time-sensitive nature of this problem. Closer to process startup there is more just-in-time translation going on. This lock is only held when code is being modified. If you fork later, you are less likely to have JIT happening on the source process then when you have fork happening on a fresh process. Just-in-time compilation will also be slower on slower machines, such as on a raspberry Pi, than on a DevKit, augmenting the chance fork happens while parts of JIT are still happening on other threads. For the Cygwin/fork experts in this thread, does what I just said ring a bell? |
You may need to try asking in cygwin@cygwin.com mailing list, I don't know if any cygwin fork experts are present here. https://cygwin.com/pipermail/cygwin/2024-July/256271.html is the latest in my thread there, IIRC |
When running `pacman` on Windows/ARM64, we frequently run into curious hangs (see msys2/msys2-autobuild#62 for more details). This commit aims to work around that by replacing the double-fork with a single-fork in `_gpgme_io_spawn()`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This sounds highly plausible to me.
That is quite an interesting aspect. Now the question is only: would this lock be lifted automatically if the thread lived just a little longer? And maybe the problem is that the Cygwin process exits before those threads could all be joined, assuming that it can rely on I wonder whether we can detect that situation in the Cygwin/MSYS2 runtime somewhere close to where the thread is terminating, or maybe this can be done in the emulator just before the thread ends? Also: would you have any hints how this could be debugged by someone like me, @pmsjt? Maybe some WinDbg wizardry? |
This might actually be precisely what the suggested |
On Wed, 8 May 2024, Jeremy Drake wrote: > (this is the same issue discussed in > https://cygwin.com/pipermail/cygwin-patches/2024q1/012621.html) > > On MSYS2, running on Windows on ARM64 only, we've been plagued by issues > with processes hanging up. Usually pacman, when it is trying to validate > signatures with gpgme. When a process is hung in this way, no debugger > seems to be able to attach properly. > > > anecdotally, the hang occurs when _exit() calls > > proc_terminate() which is then blocked by a call to TerminateThread() > > with an invalid thread handle (for more details, see > > msys2/msys2-autobuild#62 (comment)). As a follow-up to this, that was from a proposed workaround of just commenting out the double-fork behavior in gpgme. After reading a comment in the code and doing some research online, it seems the double-fork is an accepted idiom on posix to avoid having to wait for the (grand)child, without creating zombie processes. I was unable to see zombie processes in ps or /proc/<pid>, but I did see extra cygpid.* entries in /proc/sys/BaseNamedObjects/cygwin* which seem to be much the same thing. Today, I was attempting to look at the TerminateThread situation. The call in question comes from the attempt to terminate the wait_thread of a chld_procs entry. I noticed elsewhere in cygwin code (flock.cc) that CancelSynchronousIo was being called, and that stood out to me because chances are that the wait thread (if running) is going to be blocked in ReadFile. I am testing with the following hack, and so far have not seen a hang: Applied-from: https://inbox.sourceware.org/cygwin-developers/23f23b0a-e60e-e3ff-4c1e-295599fdc813@jdrake.com/ Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Just so we have an issue to link to and discuss maybe
The text was updated successfully, but these errors were encountered: