Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313082 - Race condition in StreamCopyThread
Summary: Race condition in StreamCopyThread
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 0.8.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-17 04:44 EDT by Dmitry Neverov CLA
Modified: 2010-05-19 14:41 EDT (History)
1 user (show)

See Also:


Attachments
patch to fix problem (868 bytes, patch)
2010-05-17 04:45 EDT, Dmitry Neverov CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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