Skip navigation
3256 Views 1 Reply Latest reply: Sep 16, 2009 7:53 AM by Guenther Niess RSS
gperrot Bronze 11 posts since
Jul 1, 2008
Currently Being Moderated

Sep 16, 2009 7:08 AM

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 </stream> 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.

Attachments:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points