Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341508 - Errors in log when running tests: [Fatal Error] :1:1: Premature end of file.
Summary: Errors in log when running tests: [Fatal Error] :1:1: Premature end of file.
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: 3.7   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.7 M7   Edit
Assignee: Ian Bull CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 339862 (view as bug list)
Depends on:
Blocks: 340737
  Show dependency tree
 
Reported: 2011-03-31 11:28 EDT by DJ Houghton CLA
Modified: 2011-04-02 02:40 EDT (History)
3 users (show)

See Also:


Attachments
Patch v1 (1.93 KB, patch)
2011-03-31 14:04 EDT, Ian Bull CLA
no flags Details | Diff
mylyn/context/zip (16.88 KB, application/octet-stream)
2011-03-31 14:04 EDT, Ian Bull CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description DJ Houghton CLA 2011-03-31 11:28:03 EDT
I've been looking at the console logs lately from the test suite runs, and I've seen a lot of these messages:
   [Fatal Error] :1:1: Premature end of file.

I'm trying to track down where this is coming from. I think it might be related to some code in the SimpleArtifactRepository. Specifically here is some of the stack:

SimpleArtifactRepositoryIO$Parser.parse(InputStream) line: 310	
SimpleArtifactRepositoryIO.read(URI, InputStream, IProgressMonitor, boolean) line: 101	
SimpleArtifactRepositoryFactory.load(URI, int, IProgressMonitor, boolean) line: 107	
SimpleArtifactRepository.doLoad(IProgressMonitor) line: 1442	
SimpleArtifactRepository.load(IProgressMonitor) line: 1399	
SimpleArtifactRepository.getRules() line: 905	
SimpleArtifactRepositoryIO$Writer.write(SimpleArtifactRepository) line: 231	
SimpleArtifactRepositoryIO.write(SimpleArtifactRepository, OutputStream) line: 64	
SimpleArtifactRepository.save(boolean) line: 1148	
SimpleArtifactRepository.save() line: 1115	
SimpleArtifactRepository.doSetProperty(String, String, IProgressMonitor, boolean) line: 1177	
SimpleArtifactRepository.setProperty(String, String, IProgressMonitor) line: 1189	
SimpleArtifactRepository(AbstractRepository).setProperty(String, String) line: 190	

I think this is a new repository being created. The file on disk is 0 length which makes sense, we've opened a stream and started writing to it but then we try and read the mapping rules from disk and can't. This is the suspicious code in #getRules():

public synchronized String[][] getRules() {
	if (!holdsLock() && URIUtil.isFileURI(getLocation())) {
		load(new NullProgressMonitor());
	}
	return mappingRules;
}

I believe we should have some protection there to know whether or not we are in the middle of a "write" operation or if we don't believe the repo should exist.
Comment 1 Ian Bull CLA 2011-03-31 11:49:56 EDT
Thanks DJ.  I was looking at this yesterday, trying to figure out if this was a new problem.  I'll take this one.
Comment 2 Ian Bull CLA 2011-03-31 13:27:42 EDT
(In reply to comment #0)
> 
> public synchronized String[][] getRules() {
>     if (!holdsLock() && URIUtil.isFileURI(getLocation())) {
>         load(new NullProgressMonitor());
>     }
>     return mappingRules;
> }
> 
> I believe we should have some protection there to know whether or not we are in
> the middle of a "write" operation or if we don't believe the repo should exist.

the !holdsLock() is supposed to protect against this.  That is, if we are currently writing we should have the lock and not re-load the rules.  I did some digging, and appears that we think this area is 'read-only', so we never acquire a lock (we cannot lock a read only area). Obviously the area is not read-only (or we would not be saving).  I need to review the logic for checking if an area is read-only.
Comment 3 Ian Bull CLA 2011-03-31 13:49:24 EDT
When a file does not exist, calling file#canWrite returns false. However, this doesn't mean the area is readOnly.  To properly check, I need to traverse to the parent and see if we can write there (and continue this recursively until we find a file / directory that exists and use that to determine if it's writeable).

I'm putting a fix together and running the tests now.
Comment 4 Ian Bull CLA 2011-03-31 14:04:48 EDT
Created attachment 192308 [details]
Patch v1

This moves up the parent chain to determine if location is really going to be 'read-only'.  Note, this is only for new repos, if a repo already exists, then we simple check if we can write to it.
Comment 5 Ian Bull CLA 2011-03-31 14:04:50 EDT
Created attachment 192309 [details]
mylyn/context/zip
Comment 6 Ian Bull CLA 2011-03-31 14:05:53 EDT
Fixed in head. Thanks again DJ.
Comment 7 scastria CLA 2011-04-01 12:02:24 EDT
(In reply to comment #6)
> Fixed in head. Thanks again DJ.

I wanted to double check if this fix will correct the behavior I am seeing with 3.7M6a.

1. If eclipse tries to resolve a target definition pointing to a P2 repo that is read only, it fails because it can't create the .lock file.
2. Why is eclipse trying to lock a P2 repo on a read, shouldn't this only happen with a write?
3. If I run as a user that has write privs to the P2 repo, the target definition resolution works fine, but creates a lock file.  That lock file never goes away even after exiting eclipse causing it to remain locked forever.
Comment 8 Ian Bull CLA 2011-04-01 13:01:06 EDT
This problem was related to trying to create a repository, and our implementation assuming that the area was read-only (when it wasn't). It may fix your issue, but I've opened bug 341648 to double check.

As for your other concerns:

2. This is tricky.  We need to be mindful that two separate processes may be reading / writing the same location at the same time.  In this case, you don't want the artifacts.xml to disappear as your trying to read it. Having said that, we may have to forgo the read locks as they are causing problems and we don't see any other viable solution.  This is being tracked in bug 341266.

3. This is how OSGi locking works.  The file remains, although it doesn't mean that the file is 'locked' (you've relinquished the lock on the file).  Same thing happens in your workspace/.metadata directory (after you exit eclipse, you have a .lock file).  We may want to look at the file permissions we set on the file, to make it easier to remove (set it to rw-rw-rw- for example).
Comment 9 Thomas Hallgren CLA 2011-04-02 02:40:19 EDT
*** Bug 339862 has been marked as a duplicate of this bug. ***