Possible Major Bug: CachedResourceSet holds state over boundary of Ant run. [message #1855781] |
Thu, 03 November 2022 00:49 |
|
We believe we have found a bug in the implementation of the model state handling. When running ant in the Eclipse JVM and a model instance is not read from disk every time as expected.
Instead, the same CachedResourceSet is reused and queries its cache using getCache() and then retrieves the cached instance.
The following factors hence do not correct this:
- Setting the cached attribute to false on mode load.
- Calling the disposeModels task before any other task.
We would need to ensure that CachedResourceSet is not used for Ant executions.
Alternatively, it should be possible to clear() the cache.
The problem is caused by the resource counting where multiple checkouts need to be cancelled in returnResource(). If an ant build breaks, the loans counter increases. There is no finally clause in ant, so it is not possible to dispose models on a failure to be safe.
It seems that the model repository allocated to ant runs is always the same, so the ModelRepositoryManager connects to the same underlying caches. Maybe a new ModelRepository could be allocated per Ant execution?
[Updated on: Thu, 03 November 2022 01:19] Report message to a moderator
|
|
|
Re: Possible Major Bug: CachedResourceSet holds state over boundary of Ant run. [message #1855785 is a reply to message #1855781] |
Thu, 03 November 2022 08:23 |
|
Hi Jörn,
This shouldn't be happening as there is a build listener in place, that should dispose all models in the repository on failure. I've tried with a small example (load EMF model, consume it in an EOL program that throws an exception) and it seems to be working as expected. Could you please put together a small example I can use to reproduce the behaviour you're encountering? In the meanwhile, you could use the "Model Cache" view in Eclipse to inspect and clear the contents of the cache.
Thanks,
Dimitris
|
|
|
Re: Possible Major Bug: CachedResourceSet holds state over boundary of Ant run. [message #1855802 is a reply to message #1855785] |
Fri, 04 November 2022 04:46 |
|
I think we have found the underlying issue, but we are unsure how to address it. We have two models that are loaded and one holds a reference to the other. We can see the disposal code in the Cache is called. However, it seems the failure to disposal is related to the fact that the resource is once loaded explicitly, which is reference-counted and tracked, and once lazily and implicitly which is not. As a result, the model stays in memory.
|
|
|
Re: Possible Major Bug: CachedResourceSet holds state over boundary of Ant run. [message #1855804 is a reply to message #1855802] |
Fri, 04 November 2022 04:59 |
|
I think it is this code in org.eclipse.emf.ecore.resource.impl.ResourceSetImpl. It will load the resource in the resource list on demand, bypassing createNewResource and the cache.
public EObject getEObject(URI uri, boolean loadOnDemand)
{
Resource resource = getResource(uri.trimFragment(), loadOnDemand);
if (resource != null)
{
return resource.getEObject(uri.fragment());
}
else
{
return null;
}
}
|
|
|
Re: Possible Major Bug: CachedResourceSet holds state over boundary of Ant run. [message #1855809 is a reply to message #1855804] |
Fri, 04 November 2022 07:59 |
|
OK - I've reproduced the issue with two models that reference each other. I've created an issue for this.
Until this gets fixed (PRs more than welcome now that we've moved to GitHub!), a workaround would be to add the following JavaScript task to the build file and clear the EMF driver's resource cache before your model loading tasks.
<script language="javascript">
with(new JavaImporter(org.eclipse.epsilon.emc.emf)){
CachedResourceSet.getCache().clear();
}
</script>
Thanks,
Dimitris
|
|
|
Powered by
FUDForum. Page generated in 0.03399 seconds