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

Bug 452962

Summary: Improve Session resources cleanup on close
Product: [Modeling] Sirius Reporter: Esteban DUGUEPEROUX <esteban.dugueperoux>
Component: CoreAssignee: Laurent Redor <laurent.redor>
Status: CLOSED FIXED QA Contact: Laurent Fasani <laurent.fasani>
Severity: normal    
Priority: P3 CC: belqassim.djafer, florian.barbin, laurent.fasani, laurent.redor, pierre-charles.david
Version: 2.0.0Keywords: triaged
Target Milestone: 3.0.0M6   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/37974
https://git.eclipse.org/r/42271
https://git.eclipse.org/r/42308
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=0fb7177d285bcd60589afcc87949e19ea818bcf0
https://git.eclipse.org/r/42495
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=4262fc18fbf99dfd33cef7ebbdfe7104a4928339
https://git.eclipse.org/r/42514
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=4716ad1c3a42bc898751657b505cb15e8e205fc3
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=287cbe05bdac112d652dd5253cb28f58244f5c4d
https://git.eclipse.org/r/42743
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=1c7f627141c23d0b531aed77250be33321802ca0
https://git.eclipse.org/r/42757
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=81a8b1f44c065dd8dfd198e33d66e4eca395c04d
https://git.eclipse.org/r/43674
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=bab2f4ee2811fb865404f7e9bd259565b7ee3cd0
https://git.eclipse.org/r/43684
https://git.eclipse.org/r/43685
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=5440d7845d7994b4d4bb2f31b63dd93b6d59e2fa
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=daee88ab7a8c76396ba035c65fdcd2612a721208
https://git.eclipse.org/r/44016
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=8e8e1ac2397afaa634773377db8fdabbb4aed681
Whiteboard:

Description Esteban DUGUEPEROUX CLA 2014-11-24 03:28:48 EST
When analysing memory at session closing we see fields not correctly reset.
Then this bugzilla is to improve Session resources cleanup on close.
Comment 1 Esteban DUGUEPEROUX CLA 2014-11-24 03:32:13 EST
https://git.eclipse.org/r/36898 has been submitted to Gerrit.
Comment 2 Esteban DUGUEPEROUX CLA 2014-12-04 11:34:03 EST
Fixed as 29322aa34cf733e96ea27364c38f8686dd66c43c
Comment 5 Eclipse Genie CLA 2015-02-20 06:20:21 EST
New Gerrit change created: https://git.eclipse.org/r/42271
Comment 6 Eclipse Genie CLA 2015-02-20 10:09:00 EST
New Gerrit change created: https://git.eclipse.org/r/42308
Comment 9 Eclipse Genie CLA 2015-02-24 07:37:29 EST
New Gerrit change created: https://git.eclipse.org/r/42514
Comment 12 Eclipse Genie CLA 2015-02-26 06:01:38 EST
New Gerrit change created: https://git.eclipse.org/r/42743
Comment 14 Eclipse Genie CLA 2015-02-26 08:22:03 EST
New Gerrit change created: https://git.eclipse.org/r/42757
Comment 16 Esteban DUGUEPEROUX CLA 2015-03-02 11:03:11 EST
Fixed.
Comment 17 Laurent Redor CLA 2015-03-11 06:50:27 EDT
The commit [1] 1c7f627 - "Have Saver registration done in a single place and correctly" will be reverted. It causes some regressions (deadlock) detected by a customer's use case. A scenario corresponding to this use case will be provided later (after customer's use case analysis).

[1] http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=1c7f627141c23d0b531aed77250be33321802ca0
Comment 18 Eclipse Genie CLA 2015-03-11 08:36:24 EDT
New Gerrit change created: https://git.eclipse.org/r/43674
Comment 20 Laurent Redor CLA 2015-03-11 11:06:58 EDT
Deadlock scenario with EcoreTools (associated with comment 17):
* Launch a workspace with EcoreTools
* Create a new ModelingProject (use default value except for the name of the project)
* Sometimes (several creations are potentially needed to observe the problem) there is a deadlock. The "New Ecore Modeling Project" wizard freezes with the message "Create modeling resources:"

In this case the stacks corresponding to the lock are:
* Thread [main] (Suspended)	
	OS.Call(long, long, int, int) line: not available [native method]	
	Display.sleep() line: 4044	
	ModalContext$ModalContextThread.block() line: 174	
	ModalContext.run(IRunnableWithProgress, boolean, IProgressMonitor, Display) line: 388	
	WizardDialog.run(boolean, boolean, IRunnableWithProgress) line: 1028	
	EcoreModelerWizard.performFinish() line: 229	
	WizardDialog.finishPressed() line: 827	
	WizardDialog.buttonPressed(int) line: 432	
* Thread [Worker-11] (Suspended)	
	owns: AtomicBoolean  (id=86)	
	waiting for: Object  (id=85)	
	Object.wait(long) line: not available [native method]	
	Object.wait() line: 503	
	ThreadJob.waitForRun(ThreadJob, IProgressMonitor, InternalJob, Thread) line: 270	
	ThreadJob.joinRun(ThreadJob, IProgressMonitor) line: 197	
	ImplicitJobs.begin(ISchedulingRule, IProgressMonitor, boolean) line: 92	
	JobManager.beginRule(ISchedulingRule, IProgressMonitor) line: 286	
	WorkManager.checkIn(ISchedulingRule, IProgressMonitor) line: 118	
	Workspace.prepareOperation(ISchedulingRule, IProgressMonitor) line: 2282	
	Workspace.run(IWorkspaceRunnable, ISchedulingRule, int, IProgressMonitor) line: 2339	
	Workspace.run(IWorkspaceRunnable, IProgressMonitor) line: 2326	
	IsModifiedSavingPolicy(AbstractSavingPolicy).save(Iterable<Resource>, Map<?,?>, IProgressMonitor) line: 69	
	DAnalysisSessionImpl$1.run() line: 817	
	DAnalysisSessionImpl.doSave(Map<?,?>, IProgressMonitor, boolean) line: 837	
	Saver.saveNow(Map<?,?>, IProgressMonitor, boolean) line: 115	
	Saver.save(Map<?,?>, IProgressMonitor) line: 87	
	DAnalysisSessionImpl.save(Map<?,?>, IProgressMonitor) line: 787	
	DAnalysisSessionImpl.save(IProgressMonitor) line: 782	
	SaveSessionJob.run(IProgressMonitor) line: 67	
	Worker.run() line: 54	
* Thread [ModalContext] (Suspended)	
	owns: EcoreModelingProjectCreationOperation  (id=179)	
	waiting for: AtomicBoolean  (id=86)	
	Saver.saveNow(Map<?,?>, IProgressMonitor, boolean) line: 112	
	Saver.save(Map<?,?>, IProgressMonitor) line: 87	
	DAnalysisSessionImpl.save(Map<?,?>, IProgressMonitor) line: 787	
	DAnalysisSessionImpl.save(IProgressMonitor) line: 782	
	EcoreModelingProjectCreationOperation.createModelingResources(IProject, IProgressMonitor) line: 262	
	EcoreModelingProjectCreationOperation.execute(IProgressMonitor) line: 139	
	WorkspaceModifyOperation$1.run(IProgressMonitor) line: 106	
	Workspace.run(IWorkspaceRunnable, ISchedulingRule, int, IProgressMonitor) line: 2344	
	EcoreModelingProjectCreationOperation(WorkspaceModifyOperation).run(IProgressMonitor) line: 118	
	ModalContext$ModalContextThread.run() line: 121
Comment 21 Laurent Redor CLA 2015-03-11 11:50:02 EDT
By analysis the above stacks, we can see clearly the deadlock:

NEED THE LOCK ON workspace
	Workspace.run(IWorkspaceRunnable, IProgressMonitor) line: 2326	
	IsModifiedSavingPolicy(AbstractSavingPolicy).save(Iterable<Resource>, Map<?,?>, IProgressMonitor) line: 69	
	DAnalysisSessionImpl$1.run() line: 817	
	DAnalysisSessionImpl.doSave(Map<?,?>, IProgressMonitor, boolean) line: 837	
	Saver.saveNow(Map<?,?>, IProgressMonitor, boolean) line: 115	
TAKE LOCK ON Saver.isSaving
	Saver.save(Map<?,?>, IProgressMonitor) line: 87	
	DAnalysisSessionImpl.save(Map<?,?>, IProgressMonitor) line: 787	
	DAnalysisSessionImpl.save(IProgressMonitor) line: 782	
	SaveSessionJob.run(IProgressMonitor) line: 67

NEED THE LOCK ON Saver.isSaving
        Saver.saveNow(Map<?,?>, IProgressMonitor, boolean) line: 112	
	Saver.save(Map<?,?>, IProgressMonitor) line: 87	
	DAnalysisSessionImpl.save(Map<?,?>, IProgressMonitor) line: 787	
	DAnalysisSessionImpl.save(IProgressMonitor) line: 782	
	EcoreModelingProjectCreationOperation.createModelingResources(IProject, IProgressMonitor) line: 262
        ...
LAUNCH ANOTHER THREAD
        saveSessionJob.schedule();
	...
	SaveSessionWhenNoDialectEditorsListener.statusesChanged(Collection<ResourceStatusChange>) line: 121	
	ResourceSetSync.notifyClientsInBatch(Collection<ResourceStatusChange>) line: 371	
	ResourceSetSync.resourceSetChanged(ResourceSetChangeEvent) line: 134	
	...
	TransactionalEditingDomainImpl.postcommit(InternalTransaction) line: 771	
	...	
	WorkspaceCommandStackImpl(AbstractTransactionalCommandStack).execute(Command) line: 219	
	EcoreModelingProjectCreationOperation.createModelingResources(IProject, IProgressMonitor) line: 259	
	EcoreModelingProjectCreationOperation.execute(IProgressMonitor) line: 139	
	WorkspaceModifyOperation$1.run(IProgressMonitor) line: 106
TAKE LOCK ON workspace	
	Workspace.run(IWorkspaceRunnable, ISchedulingRule, int, IProgressMonitor) line: 2344	
	EcoreModelingProjectCreationOperation(WorkspaceModifyOperation).run(IProgressMonitor) line: 118	
	ModalContext$ModalContextThread.run() line: 121
Comment 22 Eclipse Genie CLA 2015-03-12 04:42:30 EDT
New Gerrit change created: https://git.eclipse.org/r/43684
Comment 23 Eclipse Genie CLA 2015-03-12 04:42:35 EDT
New Gerrit change created: https://git.eclipse.org/r/43685
Comment 26 Eclipse Genie CLA 2015-03-17 10:58:21 EDT
New Gerrit change created: https://git.eclipse.org/r/44016
Comment 29 Laurent Redor CLA 2015-03-19 04:47:14 EDT
The last detected regression has been fixed with http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=8e8e1ac2397afaa634773377db8fdabbb4aed681
Comment 30 Belqassim Djafer CLA 2015-04-13 04:05:20 EDT
Verified as technical issue
Comment 31 Laurent Fasani CLA 2015-05-26 04:06:58 EDT
(In reply to Laurent Redor from comment #20)
scenario tested 5 times with success
Comment 32 Pierre-Charles David CLA 2015-06-24 11:13:20 EDT
Available in Sirius 3.0.0. See https://wiki.eclipse.org/Sirius/3.0.0.