Skip to content

Disconnect sentinel is compared against the response instead of the request line #12

Description

@dmccoystephenson

Problem

The server's disconnect check compares the wrong string. MSThread.java:30-40:

public void run() {
    while (readNextLine()) {
        processInput();
        sendResponseToClient();

        if (outputLine.equals("END_OF_CONNECTION")) {
            disconnect();
            break;
        }
    }
}

outputLine is the server's own response, assigned at line 87 from protocol.processInput(inputLine). Every return path in Protocol builds a Message and returns its toString(), which is always a key=value, string — so outputLine can never equal END_OF_CONNECTION, the branch is dead, and disconnect() is unreachable from run().

The sentinel is sent by the client as input, not output. Client.java:45-47:

public void disconnect() {
    sendStringToServer("END_OF_CONNECTION");
}

That arrives as inputLine, where Protocol.fromString finds no = and so records no keys, making get("process") return null and the switch at Protocol.java:18 throw into the broad catch. The client is answered success=false,reason=Something went wrong when processing input., instead of having its connection closed.

Evidence

Read from src/SimpleServer/server/MSThread.java (lines 30-40, 86-88), src/SimpleServer/client/Client.java (lines 45-47), src/SimpleServer/Message.java (fromString, lines 37-77), and src/SimpleServer/server/Protocol.java (lines 10-41).

The runtime behaviour described — the dead branch, the NullPointerException on the switch, and the response the client actually receives — is UNVERIFIED. No compile or socket run was performed in the session that filed this issue. The mismatch between outputLine and the sentinel is source-verifiable; its consequences are inferred.

Proposed change

The comparison should be made against inputLine, and the streams should be closed along with the socket when the connection ends.

Note for whoever implements this

A fix here needs a real socket run to demonstrate — the connection closing is observable only over the wire, and there is no CI in this repository to catch a regression.


This issue was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

drafted by Claude on behalf of Daniel Stephenson

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions