Author: toad
Date: 2008-11-06 18:17:47 +0000 (Thu, 06 Nov 2008)
New Revision: 23357

Modified:
   trunk/freenet/src/freenet/node/NodeClientCore.java
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
Avoid writing config file with inaccurate list of plugins. This is a race 
condition, with plugin loading running in parallel with config writing.
Start plugins synchronously, but in the off-thread initialisation completion, 
after we have finished starting fproxy.
If we haven't started yet, and are asked for a list of plugins to write to 
disk, write the list of plugins that we inherited.


Modified: trunk/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeClientCore.java  2008-11-06 17:49:08 UTC 
(rev 23356)
+++ trunk/freenet/src/freenet/node/NodeClientCore.java  2008-11-06 18:17:47 UTC 
(rev 23357)
@@ -506,6 +506,7 @@
                                // But it does other things too
                                fcpServer.finishStart();
                                persistentTempBucketFactory.completedInit();
+                               node.pluginManager.start(node.config);
                                // FIXME most of the work is done after this 
point on splitfile starter threads.
                                // So do we want to make a fuss?
                                // FIXME but a better solution is real request 
resuming.

Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2008-11-06 
17:49:08 UTC (rev 23356)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2008-11-06 
18:17:47 UTC (rev 23357)
@@ -26,6 +26,7 @@

 import freenet.client.HighLevelSimpleClient;
 import freenet.clients.http.PageMaker.THEME;
+import freenet.config.Config;
 import freenet.config.InvalidConfigValueException;
 import freenet.config.SubConfig;
 import freenet.keys.FreenetURI;
@@ -150,21 +151,32 @@
                                }
                        });

-               String fns[] = pmconfig.getStringArr("loadplugin");
-               if(fns != null)
-                       for(String name : fns)
-                               startPluginAuto(name, false);
-
+               toStart = pmconfig.getStringArr("loadplugin");
+               
                pmconfig.finishedInitialization();

                fproxyTheme = 
THEME.themeFromName(node.config.get("fproxy").getString("css"));
                selfinstance = this;
        }
+       
+       private boolean started;
+       private String[] toStart;
+       
+       public void start(Config config) {
+               if(toStart != null)
+                       for(String name : toStart)
+                               startPluginAuto(name, false);
+               synchronized(pluginWrappers) {
+                       started = true;
+                       toStart = null;
+               }
+       }

        private String[] getConfigLoadString() {
                Vector<String> v = new Vector<String>();

                synchronized(pluginWrappers) {
+                       if(!started) return toStart;
                        for(PluginInfoWrapper pi : pluginWrappers) {
                                v.add(pi.getFilename());
                        }
@@ -233,9 +245,6 @@
                synchronized(startingPlugins) {
                        startingPlugins.add(pluginProgress);
                }
-               node.executor.execute(new Runnable() {
-
-                       public void run() {
                                Logger.normal(this, "Loading plugin: " + 
filename);
                                FredPlugin plug;
                                try {
@@ -273,8 +282,6 @@
                                        if(store)
                                                core.storeConfig();
                                }
-                       }
-               }, "Plugin Starter");
        }

        class PluginLoadFailedUserAlert extends SimpleUserAlert {


Reply via email to