[jcifs] WriterThreads are leaking

Michael B Allen ioplex at gmail.com
Wed Oct 23 00:59:19 MDT 2013


On Mon, Oct 21, 2013 at 2:34 PM, Shon Vella <svella at idauto.net> wrote:
> The problem is that the currently there is no guarantee that WriterThread will have reached the wait() before the call to w.write() in the finally block if no previous write was performed in copyTo0(). This is because copyTo0() has code to ensure that WriterThread is ready before calling write(), whereas the finally block does not. While the code could be duplicated in the finally block, I think it would make more sense to move the synchronization code inside of the write() method. It would also be a very good think to mark member variables that are accessed from both threads as volatile, since without that there is no guarantee that other threads will see updated values values immediately. Something like:

Hi Shon,

So w.write( null, -1, null, 0 ) is being called to reset the
WriterThread before the WriterThread.run routine has entered the
"ready" state. That sounds very plausible. And your fix sounds exactly
correct. All WriterThread operations need to verify that the it has
first reached the ready state.

I don't think we need to use volatile though because we synchronize explicitly.

I have added your fix to the TODO list and bumped it to toward the
top. Although updates are very few and far between at this point so I
cannot make promises about when it will actually be released.

Good job diagnosing the problem and coming up with what looks like the
right fix. That doesn't happen often with JCIFS. The code can be
tricky to understand. Nice work.

Mike


More information about the jCIFS mailing list