Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Race Condition in Babun Startup #332
Under Windows XP Pro x64 (Service Pack 2), babun's desktop shortcut fails with the following depressingly familiar fatal error:
We now demonstrate this issue to be the result of a subtle race condition between Windows Explorer, Windows batch files, and Cygwin itself. We have not identified the exact underlying cause of this issue. ("Time! What is time? Reality, it hurts me so.")
Given fundamental incompatibilities between the Windows and POSIX process models, there may very well exist no genuine solution. We have, however, identified several babun-specific solutions applicable by both end users and babun developers – each resolving this issue with varying degrees of success.
Let's get to it, shall we?
Or, How We Know It's a Race Condition and not BLODA
We first installed babun onto a spare laptop recently formatted with Windows XP Pro x64 (Service Pack 2) with all available updates. Babun's desktop shortcut repeatably yields the above error. Suspecting BLODA, we grep for verboten services, processes, and dynamic libraries (especially third-party antivirus software). We fail. Thanks to the unicorn-like magic of formatting, the system appears to be clean. No bloody BLODA.
In abject desperation, we run the
As we know, BLODA lurks in the darkest corners of every registry. A requisite device driver (say, any of the various Nvidia nForce motherboard drivers installed for this laptop) could conceivably be performing DLL hook injection. Incidentally, what sort of OS permits a process to inject arbitrary code into the address space of other processes? We digress.
To eliminate the unlikely (but possible) possibility of driver-based BLODA, we next installed babun onto an Ubuntu Linux VirtualBox-hosted Windows XP Pro x64 guest (Service Pack 2) with all available updates. No other software – either first- or third-party – is installed. Babun's it, baby. Unless VirtualBox itself or VirtualBox's Guest Additions perform DLL hook injection, BLODA is right out. Neither of them appear to, so BLODA is right out. So Babun just works!
Just kidding. Babun's desktop shortcut repeatably yields the above error. Here's where things get smelly. Whereas this shortcut always fails on the laptop, it only fails approximately half of the time on the VirtualBox guest. The other half of the time, babun starts as expected into a Cygwin-based MinTTY terminal. All startup checks succeed. We begin to get that lunatic gleam in our eyes. ("We will fix this. Oh, yesss.") Sanity, you have met your match.
We inspect the
Keep it simple, right? But that doesn't actually help us with anything. We try echoing out the values of
The error goes away. Wat? Yes, insanity walks among us. Adding two echo statements to the top of
Under sane operating systems and scripting languages, output has no side effect other than output. But this is Windows. If it's terrible, it's possible. We delve deeper into madness by prefixing each of the prior
This will effectively revert our changes and re-expose the error! It doesn't. The error continues to occur 7% of the time. We remove the
We tear out a fistful of hair, screaming to the penitent sky: "WHY, WHY, WHY." Then we... remember.
Given that, what do
Given that, why does slowing down a batch script when executing a previously failing program cause that program to succeed with greater frequency? Again, there's only one answer: a fatal race condition.
Or, How We Know It's a Windows Explorer <-> Batch Script Race Condition
"Oh, it must be a Cygwin-wide race condition!", you bleat. Right? Wrong.
We revert all of our changes and try:
Did you ever play logic puzzles when you were a kid? I did. Lots. (That probably explains a few things.) This is like those, only fun-less. We were tempted to draw up a Markdown-based table synopsizing the logic puzzle defined by the above findings. But we're tired... and so are you.
So the syllogistic conclusion is clear: there exists a race condition in babun's startup batch script when run (either directly or via a shortcut) from the Windows Explorer under Windows XP Pro x64.
Let's talk "solutions."
For End User Eyes Only
If you're an end user and just want babun to work fergodsakes, the simplest and most reliable solution is to:
A less simple and less reliable solution is to add an absurd number of
For Developer Eyes Only
If you're a developer and graciously want to try fixing this, the simplest and most reliable solution is to edit babun's installation batch script to also install a shortcut to
For systems on which Cygwin has not been previously installed, babun's startup batch script seems to serve no purpose. MinTTY seems to give the same results, with the added bonus of no race conditions.
For systems on which Cygwin has been previously installed, babun's startup batch script seems to serve the purpose of redefining
If so, our recommendation is to remove
We're tired. This was an absurd issue, and the fixes are equally absurd. The underlying issue is probably infeasible to debug and certainly infeasible to fix. Installing a desktop shortcut to babun's MinTTY appears to be the least bad of only bad options.
Welcome to Windows.
wow, this is the most scary yet most enjoyable bug description I've ever read.
In the early releases we had some good reasons to start babun via the bat script but right now I do not see any. We can make the desktop shortcut point straight to mintty and squash this change into the next release.
This would work for everybody who install babun from scratch, but not for those who will update it via
Wow! Thanks for the earnest acknowledgement. I did try to inject a bit of levity into the whole affair. It was pretty frustrating to debug. I was keen to see that no one hit that same threshold of unmitigated suffering.
Right. I figured you had sensible reasons, but that this might be vestigial now.
Yay! You are champions among Github men. Thanks for attending to this so swiftly.
Not at all! That'd be awesome, in fact. Spread the good cheer, I say.
referenced this issue
Jul 29, 2015
Nice! This appears to have fixed the slow prompt! I would often get the results of a command back quickish but the prompt was taking ages to reappear, very frustrating! changing the babun.bat and making a new desktop shortcut appears to have fixed it for me. Thank you very much, this has bothered me for a while now over multiple machines!