Skip to content

Commit 352a044

Browse files
committed
fixes #238: Release references provided by unloaded plugins
When another plugin provides a Statistic instance, that instance should be released when the provider unloads. Failing to do so will prevent that plugin's classloader from being destroyed. This can cause all kinds of unexpected side-effects. This commit removes references to _all_ Statistic instances whenever _any_ plugin unloads. That's a buckshot, but the effects should be limited to missing stats around the time that a plugin gets unloaded/reloaded - which is expected to be very rare.
1 parent 67a0f7f commit 352a044

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

changelog.html

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ <h1>
4848
<ul>
4949
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/232'>Issue #232</a>] - Fix SQL issue when retrieving archived messages from MSSQL</li>
5050
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/235'>Issue #235</a>] - Plugin compatible with Openfire 4.8.0</li>
51+
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/238'>Issue #238</a>] - Ensure that Statistics provided by unloaded plugins are no longer referenced.</li>
5152
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/240'>Issue #240</a>] - Stop using javascript libraries that are removed from Openfire 4.8</li>
5253
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/242'>Issue #242</a>] - Fix 'Unable to save XML properties' error</li>
5354
</ul>

src/java/org/jivesoftware/openfire/plugin/MonitoringPlugin.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 Jive Software. All rights reserved.
2+
* Copyright (C) 2008 Jive Software, 2022 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
3838
import org.jivesoftware.openfire.archive.GroupConversationInterceptor;
3939
import org.jivesoftware.openfire.archive.MonitoringConstants;
4040
import org.jivesoftware.openfire.container.Plugin;
41+
import org.jivesoftware.openfire.container.PluginListener;
4142
import org.jivesoftware.openfire.container.PluginManager;
4243
import org.jivesoftware.openfire.http.HttpBindManager;
4344
import org.jivesoftware.openfire.reporting.graph.GraphEngine;
@@ -62,7 +63,8 @@
6263
*
6364
* @author Matt Tucker
6465
*/
65-
public class MonitoringPlugin implements Plugin {
66+
public class MonitoringPlugin implements Plugin, PluginListener
67+
{
6668

6769
/**
6870
* The context root of the URL under which the public web endpoints are exposed.
@@ -200,6 +202,8 @@ public boolean accept(File pathname) {
200202

201203
loadPublicWeb(pluginDirectory);
202204

205+
manager.addPluginListener(this);
206+
203207
statsEngine.start();
204208
statisticsModule.start();
205209
conversationManager.start();
@@ -218,6 +222,8 @@ public void destroyPlugin() {
218222

219223
unloadPublicWeb();
220224

225+
XMPPServer.getInstance().getPluginManager().removePluginListener(this);
226+
221227
if (messageIndexer != null) {
222228
messageIndexer.stop();
223229
messageIndexer = null;
@@ -349,4 +355,17 @@ public GraphEngine getGraphEngine() {
349355
public StatsViewer getStatsViewer() {
350356
return statsViewer;
351357
}
358+
359+
@Override
360+
public void pluginCreated(String s, Plugin plugin)
361+
{}
362+
363+
@Override
364+
public void pluginDestroyed(String s, Plugin plugin)
365+
{
366+
// Restart the statsEngine to get rid of references to classes from the Plugin that's being unloaded. Fixes issue #238.
367+
if (statsEngine != null) {
368+
statsEngine.purgeDefinitions();
369+
}
370+
}
352371
}

src/java/org/jivesoftware/openfire/reporting/stats/StatsEngine.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 Jive Software. All rights reserved.
2+
* Copyright (C) 2008 Jive Software, 2022 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -98,6 +98,11 @@ public void stop() {
9898
samplingTask.cancel();
9999
}
100100

101+
public void purgeDefinitions() {
102+
definitionMap.clear();
103+
multiMap.clear();
104+
}
105+
101106
private void checkDatabase(StatDefinition[] def) throws RrdException, IOException {
102107
File directory = new File(getStatsDirectroy());
103108
if (directory.exists()) {

0 commit comments

Comments
 (0)