I just closed a case that I thought was a bit interesting. I could skip directly to the old Problem, Resolution format, but I think that most of the time there is a lot to be learned from the troubleshooting process as well, so I'll simply describe the scenario as well as what I did to resolve it.
The tools I used for troubleshooting are Visual Studio 2005 and windbg.
The customer had a web application that was using ProcessStartInfo in Visual Studio 2005 to automate Robocopy.exe. He wanted to copy large directories back and forth between servers. I don't know the number of concurrent clients for this application, but I'm guessing it was <=1. Anyway the problem wasn't multiple users, it was the fact that when he tried to copy a large directory tree the application would hang. Robocopy would still be running but the main application was completely unresponsive.
In case you're experiencing something similar yourself and are eager to find out what the actual problem was I'll tell you straight away: The standard output buffer was full. It can hold a maximum of 4k. Robocopy was waiting for the standard output buffer to be flushed, and the web application was waiting for Robocopy.
So the first tests were standard stuff, figuring out if this was due to a problem with the Robocopy application or not and to provide the customer with an acceptable alternative while troubleshooting. The customer had already found that if he turned on the "/LOG"-switch he was able to copy without problems. The "/LOG"-switch simply writes output to file rather than standard output, so this was something the customer could consider using if time was of the essence.
Since we now suspected that we somehow hit a limit in standard output it was important to find out if this problem lied within Robocopy or if any console application with massive output would cause the same problem.
I created a simple console application that accepted a single argument X and used it to dump X * 100 character lines into standard output:
I then created a simple winforms application that created an instance of this console application using ProcessStartInfo. I put a NumericUpDown-control, a button and a multi-line textbox on it. Creating a GUI that looks like this:
Finally I added the following code:
My test application worked fine with anything up to 39 lines. After that it would hang.
Since I didn't know at the time that there is a size limit for the standard output buffer I thought I'd take a look at what the two applications were doing using windbg and SOS. I reproduced the error and attached to the two processes. This is what the console application, WriteALot.exe, was doing:
Okay, so it was still writing to the standard output buffer. By dumping the stack objects I was then able to see how far along it had come:
So, apparently it was still trying to write the last line. There's nothing in the stack suggesting any behaviors out of the ordinary, so I turned my attention to the winforms application:
Apparently the winforms application was caught in the System.Threading.Thread.Sleep(10) - call. I therefore altered the application so that it would gradually read from the standard output buffer instead of trying to read it all at the end of execution:
This resolved the problem beautifully, so apparently I had identified the root cause. I searched for documented limits and pretty quickly I came up with the answer. Once you know what to look for it is actually quite well documented on MSDN.
Until next time!
/ Johan