powered by Jive Software

Smack should disconnect connections during JVM shutdown

Hi,

I’ve recognized many strange errors in the Openfire Info logs:

“An existing connection was forcibly closed by the remote host”.

Obviously they occur, if the client does not close the stream with </stream:stream>, but instead just shuts down the program.

Therefore I’ve added the following to my code:

Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                if (connection != null) {
                    // Disconnect before the JVM exits.
                    // Otherwise Openfire logs an IOException "An existing connection was forcibly closed by the remote host".
                    connection.disconnect();
                }
            }
        });

I think this is worth considering to be included into Smack. What do you think?

Obviously Smack should consider the case, when a client starts multiple sessions.

Maybe work with Connection.addConnectionCreatedListener, keep a Map or List of connections somewhere and disconnect each connection during JVM shutdown.

IMHO it’s not part of a libraries job description to keep track of the connections and disconnect them when the VM terminates.

I agree. It is an applications responsibility to manage their open resources.