Poor reconnection behavior

Hi everyone,

I noticed that a whack component is unable to react when the hosting server brutally closes the socket (ejabberd does not send when it restarts).

We have to wait to send a packet or to perform a keep alive to detect the disconnection and reconnect.

After some investigation I found that the cause is an EOFException poorly catched:

/**
     * A dedicated thread loop for reading the stream and sending incoming
     * packets to the appropriate router.
     */
    public void run() {
        try {
            readStream();
        }
        catch (EOFException eof) {
            // Normal disconnect
        }
        catch (SocketException se) {
            // Do nothing if the exception occured while shutting down the component otherwise
            // log the error and try to establish a new connection
            if (!shutdown) {
                component.getManager().getLog().error(se);
                component.connectionLost();
            }
        }
        catch (XmlPullParserException ie) {
            component.getManager().getLog().error(ie);
        }
        catch (Exception e) {
            component.getManager().getLog().warn(e);
        }
    }

In that case, the EOFException must be treated exactly like a SocketException.

In fact, any fatal exception should make trigger the connection error (if the component is not shutting down).

I suggest keeping only the catch will all exception like in the Smack library:

/**
     * A dedicated thread loop for reading the stream and sending incoming
     * packets to the appropriate router.
     */
    public void run() {
        try {
            readStream();
        }
        catch (Exception e) {
            // Do nothing if the exception occured while shutting down the component otherwise
            // log the error and try to establish a new connection
            if (!shutdown) {
                component.getManager().getLog().error(se);
                component.connectionLost();
            }
        }
    }

Patch attached.
whack-reconnection.patch.zip (553 Bytes)

I created WHACK-13 to track the bug.