Just double checking something: are you dealing with threads?
Argh, that was a dumb question. Pretend I didn't ask it that way.
I meant to ask:
How do you deal with threads? Is the temporary file a global resource
that the threads all touch? If so, have you done any synchronization to
make sure that at most one thread can touch the temporary file at a time?
What are the shared resources for the threads?
The situation you mentioned,
Worse yet, the first 5 messages of my test go through the entire
process without a problem, and then # 6 hits this -- but only if # 1
message is really big.
is exactly the sort of thing I'd expect if two threads were contending for
the same resource, so let's see if the bug has to do with this.