rjwut/ian

SenderThread does not terminate on IOException

Closed this issue · 1 comments

One of the best ways to detect network issues is to try to send some kind of heartbeat packet to the server (since such a packet does not exist, I was using KeystrokePacket for now). My expectation was that if the network was down (e.g. wireless disconnected) then the send would fail, causing ArtemisNetworkInterface to disconnect, and thus producing a DisconnectEvent.

However, in this situation, I'm not getting a DisconnectEvent.

Looking at the code, it looks like the SenderThread does not terminate on IOException:

try {
    pkt.writeTo(mWriter, mInterface.mDebugger);
} catch (final IOException ex) {
    if (mRunning) {
        mInterface.disconnectCause = DisconnectEvent.Cause.IO_EXCEPTION;
        mInterface.exception = ex;
    }
    break;
}

For my use case, it would be good if it did, generating a DisconnectEvent.

For what it's worth, ReceiverThread does terminate on IOException:

try {
    ...
} catch (final ArtemisPacketException ex) {
    mDebugger.onPacketParseException(ex);

    if (mRunning) {
        Throwable cause = ex.getCause();

        if (cause instanceof EOFException || cause instanceof SocketException) {
            // Parse failed because the connection was lost
            mInterface.disconnectCause = DisconnectEvent.Cause.REMOTE_DISCONNECT;
            mInterface.exception = (Exception) cause;
        } else {
            mInterface.disconnectCause = DisconnectEvent.Cause.PACKET_PARSE_EXCEPTION;
            mInterface.exception = ex;
        }

        end();
    }

    break;
}

If you can confirm this isn't explicitly intentional, I can do some testing locally and submit a pull request with my findings.

rjwut commented

Hmm, I'll look carefully at this and get back to you.