Bug 199573 - Threading issues in SystemTempFileListener
Summary: Threading issues in SystemTempFileListener
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P2 minor (vote)
Target Milestone: 2.0.1   Edit
Assignee: Martin Oberhuber CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-10 10:09 EDT by Martin Oberhuber CLA
Modified: 2007-09-26 21:20 EDT (History)
3 users (show)

See Also:
javier.montalvoorus: review+


Attachments
Patch to fix threading issues (2.82 KB, patch)
2007-08-10 10:13 EDT, Martin Oberhuber CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Oberhuber CLA 2007-08-10 10:09:24 EDT
There are threading issues in SystemTempFileListener:

* The _isSynching variable is not synchronized between main thread and worker
  thread, it should be marked volatile

* The _changedResources ArrayList is modified in the main thread (by clearing
  it), but at the same time another thread may call add(), this may lead to
  a ConcurrentModificationException

* In case an exception happens in the RefreshResourcesUIJob, the _isSynching
  variable is not reset so it can never sync again
Comment 1 Martin Oberhuber CLA 2007-08-10 10:13:52 EDT
Created attachment 75845 [details]
Patch to fix threading issues

Attached patch fixes the issues:

* Declare _isSynching volatile to fix multi-thread access

* Make the synchronized(_changedResources) block smaller, by first copying
  contents into a separate array then clearing the arrayList; that way, we
  are sure to never call out of the synchronized block, avoiding deadlock.

* Add synchronzied(_changedResources) around the _changedResources.add()
  call in order to avoid ConcurrentModificationException

* Put try ... finally block around the code between the _isSynching mutex
Comment 2 Martin Oberhuber CLA 2007-08-10 10:15:00 EDT
Patch committed:
[199573] Fix potential threading issues in SystemTempFileListener
   SystemTempFileListener.java  1.21

Everybody please review the changes for educational purposes. It's a very typical example of how threading issues are to be avoided in Java.