The Mangy Yak

Monday, July 10, 2006

Need RMA for my Brain

Today I spent 6 hours fighting a bug.
I think my brain has a defect. I was observing a weird behavior where some remote processes seemed to be dying earlier than they should. This only happened under I/O-intensive processes. All kinds of conjectures went through my head - from the simplest to the most complicated. I will spare you from the details.

Anyway, I was almost giving up when, all of a sudden, I saw this piece of code (blogger sucks for posting code, so cut me some slack on this):

while(true){

try{
...
}catch(){
...
}catch(){
...
}finally{

try {

if (closeOnExit)

lReader.close();

} catch (IOException ex) {

logger.error("Failed to close output stream.", ex);

}

}

}

}

This loop forwards the streams to the remote server. It only iterates when the buffer overflows, and the buffer only overflows if the flush timeout is small enough or if the process writes enough stuff to STDOUT/STDERR. So, I was essentially closing the stream on the first iteration, causing the underlying process to die earlier than I was expecting it to.

Damn. My tests weren't getting this because I use very large buffers (up to 2000 characters), and my toy test processes didn't produce that much output. When I attempted to dump the old testament on-screen (my favourite for stress tests), this odd behavior appeared.

Oh well. At least I'm getting somewhere.

0 Comments:

Post a Comment

<< Home