Server tries to parse stanza''s before it''s completely initialized

As you might have gathered from the number of threads I’‘m posting today, we’‘re running in quite a few problems. As these force us to frequently restart our server (auch), we’'re noticing a lot of unwanted behavior at server startup.

We’'re running Openfire 3.2.2.

This one is particularly nasty. Directly after a startup, we get loads of the NullPointerException that I appended to this post. The error occurs inside the second if-boolean evaluation:

public boolean isRemote(JID jid) {
        if (jid != null) {
            if (!name.equals(jid.getDomain()) && componentManager.getComponent(jid) == null) {
                return true;
            }
        }
        return false;
    }

The nullpointer exception is caused by the absence of one of two fields of the XMPPServer instance:

private InternalComponentManager componentManager;
private String name;

As far as I can see, this is caused by Openfire accepting (and trying to parse) some stanzas before the XMPPServer instance has been initialized. If this is true, it’'s quite likely that stanzas are lost.

In a quick glance, I didn’‘t detect any other place besides initialization where those fields are set. That indicates that one possible solution to this problem would be to apply the ‘‘final’’ keyword to the field declarations. I’'m aware that it requires a partial rewrite of the class, but it does guarantee that the fields are not-null after the object has been created.

The entire stack of the NullPointer follows:

Internal server error
java.lang.NullPointerException
         at org.jivesoftware.wildfire.XMPPServer.isRemote(XMPPServer.java:189)
         at org.jivesoftware.wildfire.spi.PresenceManagerImpl.probePresence(PresenceManagerImpl.java:405)
         at org.jivesoftware.wildfire.handler.PresenceUpdateHandler.initSession(PresenceUpdateHandler.java:204)
         at org.jivesoftware.wildfire.handler.PresenceUpdateHandler.process(PresenceUpdateHandler.java:104)
         at org.jivesoftware.wildfire.handler.PresenceUpdateHandler.process(PresenceUpdateHandler.java:88)
         at org.jivesoftware.wildfire.handler.PresenceUpdateHandler.process(PresenceUpdateHandler.java:151)
         at org.jivesoftware.wildfire.PresenceRouter.handle(PresenceRouter.java:123)
         at org.jivesoftware.wildfire.PresenceRouter.route(PresenceRouter.java:69)
         at org.jivesoftware.wildfire.spi.PacketRouterImpl.route(PacketRouterImpl.java:75)
         at org.jivesoftware.wildfire.net.StanzaHandler.processPresence(StanzaHandler.java:300)
         at org.jivesoftware.wildfire.net.ClientStanzaHandler.processPresence(ClientStanzaHandler.java:85)
         at org.jivesoftware.wildfire.net.StanzaHandler.process(StanzaHandler.java:225)
         at org.jivesoftware.wildfire.net.StanzaHandler.process(StanzaHandler.java:147)
         at org.jivesoftware.wildfire.nio.ConnectionHandler.messageReceived(ConnectionHandler.java:131)
         at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(AbstractIoFilterChain.java:703)
         at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
         at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:54)
         at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
         at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flush(SimpleProtocolDecoderOutput.java:62)
         at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:192)
         at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
         at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:54)
         at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
         at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:250)
         at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(ExecutorFilter.java:305)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
         at java.lang.Thread.run(Thread.java:595)

Hey Guus,

Good catch. The problem is that componentManager has a null value for a brief period after modules have been started. We need to move componentManager = getComponentManager(); in XMPPServer before startModules(); is sent. This is required both in #start and #finishSetup.

Thanks,

– Gato

I created JM-1004 for this problem.

– Gato