Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #43: Prevent ClassCastExceptions after plugin gets reloaded in a cluster #66

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

guusdk
Copy link
Member

@guusdk guusdk commented Jan 21, 2024

This plugin caches instances of classes that are defined in the code of the plugin. This causes ClassCastExceptions, when the plugin gets unloaded (removing the class definitions) and updated/reloaded (replacing the class definitions). The cached values at that time will refer to classes that no longer exist, causing the exceptions.

https://igniterealtime.atlassian.net/browse/OF-2239 introduces a new type of Cache to work around this problem, the org.jivesoftware.util.cache.SerializingCache which is available since Openfire 4.7.0. This implementation does not cache the instance directly, but caches a serialized version instead. This way, there no longer is a reference to the class, which means that any (compatible) future class definition can be used to instantiate the cache entry again.

…reloaded in a cluster

This plugin caches instances of classes that are defined in the code of the plugin. This causes ClassCastExceptions, when the plugin gets unloaded (removing the class definitions) and updated/reloaded (replacing the class definitions). The cached values at that time will refer to classes that no longer exist, causing the exceptions.

https://igniterealtime.atlassian.net/browse/OF-2239 introduces a new type of Cache to work around this problem, the org.jivesoftware.util.cache.SerializingCache which is available since Openfire 4.7.0. This implementation does not cache the instance directly, but caches a serialized version instead. This way, there no longer is a reference to the class, which means that any (compatible) future class definition can be used to instantiate the cache entry again.
@guusdk guusdk force-pushed the 43_classcastexceptions-cache branch from d5be640 to 2dc101a Compare January 21, 2024 17:09
@guusdk
Copy link
Member Author

guusdk commented Jan 21, 2024

With Openfire 4.9.0-SNAPSHOT, this generates the following runtime error, when the plugin gets initialized:

java.lang.ClassCastException: class org.jivesoftware.util.cache.CacheWrapper cannot be cast to class org.jivesoftware.util.cache.SerializingCache (org.jivesoftware.util.cache.CacheWrapper and org.jivesoftware.util.cache.SerializingCache are in unnamed module of loader org.jivesoftware.openfire.starter.JiveClassLoader @1da2cb77)
        at org.jivesoftware.util.cache.CacheFactory.createSerializingCache(CacheFactory.java:518) ~[xmppserver-4.9.0-SNAPSHOT.jar:4.9.0-SNAPSHOT]
        at org.igniterealtime.openfire.plugins.httpfileupload.OpenfireSlotProvider.<init>(OpenfireSlotProvider.java:36) ~[httpfileupload-1.4.1-SNAPSHOT.jar:?]
        at org.igniterealtime.openfire.plugins.httpfileupload.HttpFileUploadPlugin.initializePlugin(HttpFileUploadPlugin.java:413) [httpfileupload-1.4.1-SNAPSHOT.jar:?]
        at org.jivesoftware.openfire.container.PluginManager.loadPlugin(PluginManager.java:637) [xmppserver-4.9.0-SNAPSHOT.jar:4.9.0-SNAPSHOT]
        at org.jivesoftware.openfire.container.PluginMonitor$MonitorTask$4.call(PluginMonitor.java:380) [xmppserver-4.9.0-SNAPSHOT.jar:4.9.0-SNAPSHOT]
        at org.jivesoftware.openfire.container.PluginMonitor$MonitorTask$4.call(PluginMonitor.java:368) [xmppserver-4.9.0-SNAPSHOT.jar:4.9.0-SNAPSHOT]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
        at java.lang.Thread.run(Thread.java:840) [?:?]

@guusdk guusdk marked this pull request as draft January 21, 2024 17:10
@guusdk
Copy link
Member Author

guusdk commented Jan 21, 2024

I believe that the SerializableCache implementation is just ... broken? Is this being used anywhere?

I have raised these new tickets:

PR with fixes: igniterealtime/Openfire#2397

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant