Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 313082

Summary: Race condition in StreamCopyThread
Product: [Technology] JGit Reporter: Dmitry Neverov <dmitry.neverov>
Component: JGitAssignee: Project Inbox <jgit.core-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sop
Version: unspecified   
Target Milestone: 0.8.0   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
patch to fix problem none

Description Dmitry Neverov CLA 2010-05-17 04:44:37 EDT
Build Identifier: 

We should not check flushCounter.get() > 0 in catch block, because of such scenario:

StreamCopyThread                         |OtherThread
-----------------------------------------+-----------------------------------
                                         |invoke flush()
                                         |  flushCounter.incrementAndGet();
n = src.read(buf);//read smth            | 
if (flushCounter.get() > 0) continue;    |               
if (needFlush())                         |
  dst.flush(); //now flushCounter is 0   |
src.read(buf); //block on read           |
                                         |  interrupt();
//in catch:                              |
if (flushCounter.get() > 0) //false      |
throw wakey;                             |
//in finally:                            |
src.close();                             |
dst.close();                             |
                                         |//return from flush() and try to write smth to closed stream,
                                         |//get IOException("Pipe closed")

Since we use StreamCopyThrea.interrupt() for signaling it should make flush(), let's always ignore InterruptedExceptions. Patch to fix it is attached.



Reproducible: Always
Comment 1 Dmitry Neverov CLA 2010-05-17 04:45:33 EDT
Created attachment 168696 [details]
patch to fix problem
Comment 2 Shawn Pearce CLA 2010-05-19 14:41:30 EDT
Applied in b3247ba5244d95e0d2c850a3fa1f69668a5790f5