kelemen / netbeans-gradle-project

This project is a NetBeans plugin able to open Gradle based Java projects. The implementation is based on Geertjan Wielenga's plugin.
172 stars 57 forks source link

Dead-lock while starting NetBeans #23

Closed basiliscus closed 11 years ago

basiliscus commented 11 years ago

I've recently upgraded to a newer revision of the plugin (716e7951361d8ddca7e0e013b97b7258dfb87159), and the custom tasks functionality seems to be broken. I right-click on the project, select the "Custom tasks" submenu, but do not see any of my custom tasks there. Despite the tasks are defined in .nb-gradle-properties and they used to work.

Also, sometimes the plugin breaks something and Netbeans starts hanging on startup. I have to restore the IDE settings folder from time machine to bring it to life again. Not sure if those events are related, but it seems to me that the custom tasks editing dialog causes the corruption. At least, for the last time it happened right aftter that.

kelemen commented 11 years ago

To me custom tasks seem to work. Can you tell me what is your custom task definition?

Netbeans starts hanging on startup

Is this means that NetBean hangs on the splash screen? Have you used 1.1.7 as well and you did not experience it there? Anyway, it seems unlikely that the problem is related to custom tasks. Also, this seems weird because the plugin should not do anything on startup. Can you deterministically reproduce this issue on your system?

kelemen commented 11 years ago

Also, do you have the logs of NetBeans when it hangs?

basiliscus commented 11 years ago

To me custom tasks seem to work. Can you tell me what is your custom task definition?

Oops... it seems I was wrong here. My custom tasks look like this: :submodule1:gwtcompile . I expected the task would be available on every submodule node, but in fact it was available on submodule1 only. Please disregard it, my bad.

Is this means that NetBean hangs on the splash screen?

Exactly.

Have you used 1.1.7 as well and you did not experience it there?

Not sure. This is not the first time I faced the problem, but I do not remember the conditions.

Also, this seems weird because the plugin should not do anything on startup.

I temporarily disabled the plugin by editing .netbeans/7.2/config/Modules/org-netbeans-gradle-project.xml , and that solved the problem. So this does seem to be the plugin issue.

Can you deterministically reproduce this issue on your system?

I'm trying to do that...

Also, do you have the logs of NetBeans when it hangs?

I started netbeans from command line when the problem occured, and there was nothing related in the console. Is there any other place where I can look for netbeans logs?

kelemen commented 11 years ago

For tasks to be available everywhere you should uncheck "Task must exists", otherwise the plugin only checks the selected subproject and its child projects.

On Win7 the logs are stored in C:\Users\AppData\Roaming\NetBeans\7.2\var\log\messages.log. NetBeans however only keeps logs from the last three runs. On *nix, I'm not sure but probably ~/NetBeans/7.2/var/log/messages.log

basiliscus commented 11 years ago

I have found the logs: I backed up the netbeans home folder right before restoring it from the time machine. However, I do not see any errors there. If you think the logs maybe useful, how can I send it?

kelemen commented 11 years ago

A link to pastebin or a gist could be ok, just omit the initial enumeration of modules.

Although I have found a part which is dead-lock prone: org.netbeans.gradle.project.query.GradleSourceEncodingQuery. That is, if getEncoding is called from the EDT this method might dead-lock. I have had problems with character encoding in the past, so this is a notorious part of the code :). Anyway, the code is wrong, I will carefully examine it and will fix it.

Can you try to add a logging to this method and log if it is called from the EDT when NB hangs. So if you can reproduce the issue, you can examine the logs. I would try to reproduce the issue by "Run" the plugin, so it doesn't corrupt anything.

basiliscus commented 11 years ago

I haven't managed to recreate the corruption. However, I can reproduce the hanging by restoring the corrupted content of netbeans home folder.

Can you instruct me how I can supply the corrupted folder to the "run" environment? After that I will be able to debug the issue.

kelemen commented 11 years ago

I have never tried if it works but NetBeans stores the environment for "run" in "build/testuserdir", if you can copy your NetBeans user directory there it might work.

basiliscus commented 11 years ago

Ok, it has worked: I've reproduced the hanging in the run environment.

As for your question whether the method was accessed, it was not. I used the following code:

@Override
public Charset getEncoding(FileObject file) {
    Exception e = new Exception("========================== "+file);
    e.printStackTrace(System.out);
    e.printStackTrace(System.err);
kelemen commented 11 years ago

Can you run the plugin in "debug", so that you can break and inspect the callstacks of the running threads?

basiliscus commented 11 years ago

One of the suspicious threads:

java.lang.Object.wait(Object.java) java.lang.Object.wait(Object.java:485) org.openide.util.Task.waitFinished(Task.java:135) org.openide.util.RequestProcessor$Task.waitFinished(RequestProcessor.java:1708) org.netbeans.modules.project.ui.OpenProjectList$LoadOpenProjects.get(OpenProjectList.java:511) org.netbeans.modules.project.ui.OpenProjectList$LoadOpenProjects.get(OpenProjectList.java:265) org.netbeans.modules.versioning.util.DelayScanRegistry.isDelayed(DelayScanRegistry.java:89) org.netbeans.modules.git.FilesystemInterceptor$RefreshTask.run(FilesystemInterceptor.java:415) org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1452) org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2032)

I'm digging further...

basiliscus commented 11 years ago

java.lang.Object.wait(Object.java) java.lang.Object.wait(Object.java:485) org.openide.util.Task.waitFinished(Task.java:135) org.openide.util.RequestProcessor$Task.waitFinished(RequestProcessor.java:1708) org.netbeans.modules.uihandler.Installer.writeOutMetrics(Installer.java:579) org.netbeans.modules.uihandler.MetricsHandler$1WriteOut.run(MetricsHandler.java:80) org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1452) org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2032)

kelemen commented 11 years ago

NetBeans has this "check for deadlock" button in the debug menu. Does it report anything (it never worked for me though)?

basiliscus commented 11 years ago

Some more items. Niether of the stack traces seem to be related to the plugin. And the magic button didn't work :)

java.lang.Object.wait(Object.java) java.lang.Object.wait(Object.java:485) org.netbeans.modules.uihandler.Installer$SubmitAutomatic.showDialogAndGetValue(Installer.java:2491) org.netbeans.modules.uihandler.Installer$Submit.run(Installer.java:1752) org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1452) org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2032)

java.lang.Object.wait(Object.java) java.lang.Object.wait(Object.java:485) java.awt.EventQueue.invokeAndWait(EventQueue.java:1106) org.netbeans.modules.uihandler.Installer.parseButtons(Installer.java:1124) org.netbeans.modules.uihandler.Installer$Submit.doShow(Installer.java:1644) org.netbeans.modules.uihandler.Installer.displaySummary(Installer.java:1021) org.netbeans.modules.uihandler.Installer.access$400(Installer.java:113) org.netbeans.modules.uihandler.Installer$2Auto.run(Installer.java:575) org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1452) org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2032)

kelemen commented 11 years ago

Which of these threads is the EDT?

kelemen commented 11 years ago

Can you create a thread dump, though seeing all the variables would be better but it might help.

basiliscus commented 11 years ago

I don't see any EDT thread. However, the "AWT event queue" thread seems to be what we are looking for:

sun.misc.Unsafe.park(Unsafe.java) java.util.concurrent.locks.LockSupport.park(LockSupport.java:156) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1987) org.netbeans.gradle.project.WaitableSignal.tryWaitForSignal(WaitableSignal.java:39) org.netbeans.gradle.project.properties.ProjectPropertiesProxy.tryWaitForLoaded(ProjectPropertiesProxy.java:88) org.netbeans.gradle.project.NbGradleProject.tryGetLoadedProperties(NbGradleProject.java:208) org.netbeans.gradle.project.query.GradleSourceEncodingQuery.getEncoding(GradleSourceEncodingQuery.java:21) org.netbeans.modules.projectapi.ProjectFileEncodingQueryImplementation.getEncoding(ProjectFileEncodingQueryImplementation.java:76) org.netbeans.api.queries.FileEncodingQuery.getEncoding(FileEncodingQuery.java:94) org.openide.text.DataEditorSupport.openDocument(DataEditorSupport.java:583) org.apache.tools.ant.module.xml.AntProjectSupport.parseDocument(AntProjectSupport.java:271) org.apache.tools.ant.module.xml.AntProjectSupport.getDocument(AntProjectSupport.java:161) org.apache.tools.ant.module.xml.AntProjectSupport.getProjectElement(AntProjectSupport.java:316) org.apache.tools.ant.module.loader.AntProjectDataEditor.annotateWithProjectName(AntProjectDataEditor.java:121) org.apache.tools.ant.module.loader.AntProjectDataEditor.messageHtmlName(AntProjectDataEditor.java:110) org.openide.text.CloneableEditor$1.run(CloneableEditor.java:1114) org.openide.util.Mutex.doEvent(Mutex.java:1343) org.openide.util.Mutex.writeAccess(Mutex.java:457) org.openide.text.CloneableEditor.updateName(CloneableEditor.java:1111) org.netbeans.core.spi.multiview.text.MultiViewCloneableEditor.updateName(MultiViewCloneableEditor.java:186) org.openide.text.CloneableEditor.readExternal(CloneableEditor.java:1218) org.openide.windows.TopComponent$Replacer.readObject(TopComponent.java:1797) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:969) java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848) java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946) java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870) java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) org.netbeans.core.multiview.MultiViewPeer.peerReadExternal(MultiViewPeer.java:547) org.netbeans.core.multiview.MultiViewCloneableTopComponent.readExternal(MultiViewCloneableTopComponent.java:222) org.openide.windows.TopComponent$Replacer.readObject(TopComponent.java:1797) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:969) java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848) java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) org.netbeans.modules.settings.convertors.XMLSettingsSupport$SettingsRecognizer.readSerial(XMLSettingsSupport.java:549) org.netbeans.modules.settings.convertors.XMLSettingsSupport$SettingsRecognizer.instanceCreate(XMLSettingsSupport.java:581) org.netbeans.modules.settings.convertors.SerialDataConvertor$SettingsInstance.instanceCreate(SerialDataConvertor.java:424) org.netbeans.core.windows.persistence.PersistenceManager.getTopComponentPersistentForID(PersistenceManager.java:571) org.netbeans.core.windows.persistence.PersistenceManager.getTopComponentForID(PersistenceManager.java:681) org.netbeans.core.windows.PersistenceHandler.getTopComponentForID(PersistenceHandler.java:489) org.netbeans.core.windows.PersistenceHandler.load(PersistenceHandler.java:156) org.netbeans.core.windows.WindowSystemImpl.load(WindowSystemImpl.java:81) org.netbeans.core.GuiRunLevel$InitWinSys.run(GuiRunLevel.java:234) java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) java.awt.EventQueue.dispatchEventImpl(EventQueue.java:702) java.awt.EventQueue.access$400(EventQueue.java:82) java.awt.EventQueue$2.run(EventQueue.java:663) java.awt.EventQueue$2.run(EventQueue.java:661) java.security.AccessController.doPrivileged(AccessController.java) java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) java.awt.EventQueue.dispatchEvent(EventQueue.java:672) org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:158) java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296) java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211) java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201) java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196) java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188) java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

kelemen commented 11 years ago

Yes, this should be the EDT and I will try to figure out what is going on.

kelemen commented 11 years ago

And as I suspected: GradleSourceEncodingQuery.getEncoding is called on the EDT. This is rather problematic but I will try do something.

kelemen commented 11 years ago

I think this change should fix the issue you are having. Anyway, I don't know why this issue doesn't manifest more frequently.

basiliscus commented 11 years ago

Unfortunately, it doesn't seem to be solved.

  1. I pulled the sources and rebuilt the nbm.
  2. Disabled the gradle plugin in my "bad" userdir and started Netbeans from there.
  3. Closed all projects (to ensure that the issue is not project-related).
  4. Uninstalled and reinstalled the plugin.
  5. After restart netbeans hanged again :(
kelemen commented 11 years ago

I have just realized that I forgot something ... Will fix it soon. I think after this fix I will test the plugin and will release 1.1.8 and not wait for other features I wanted to add. This is a nasty issue.

kelemen commented 11 years ago

Hopefully I have removed all invokeLater from loading properties. Can you check if this finally works?

basiliscus commented 11 years ago

Yes, the issue seems to be fixed now. Thank you for fixing it so quickly and for all your efforts on this plugin.

kelemen commented 11 years ago

I'm glad it was fixed, since preventing NetBeans from loading is rather serious. Thank you for helping to track down this one. Now, I 'll test this for a few days and upload it to the Plugin Portal.