Skip to content

A failed bind is swallowed and start() then busy-loops forever #13

Description

@dmccoystephenson

Problem

A failed bind is swallowed, and the accept loop then spins without bound.

MultiServer's constructor calls initializeServerSocket() and ignores its boolean result (lines 14-17). On failure that helper prints Something went wrong while initializing with port 2000! and leaves serverSocket as null (lines 40-48).

start() then runs (lines 19-26):

public void start() {
    listening = true;

    while (isListening()) {
        System.out.println("Listening for a new connection...");
        createNewServerThread();
    }
}

createNewServerThread() calls serverSocket.accept() on the null reference, catches the resulting exception, prints ERROR: Was not able to listen on port 2000, and returns false — which the loop discards. Nothing sets listening back to false, so the loop repeats immediately and forever.

Starting a second server while port 2000 is already held is therefore expected to produce an unbounded flood of alternating "Listening for a new connection..." and "ERROR: Was not able to listen on port 2000" lines rather than an exit.

Related: stop() does not stop anything

stop() (lines 28-30) sets listening = false, but in the healthy case the loop is blocked inside accept() and will not re-test the flag until a connection arrives. serverSocket is never closed by anything in the tree.

Evidence

Read from src/SimpleServer/server/MultiServer.java, lines 14-59, and src/SimpleServer/server/ServerApp.java lines 8-12 (which hardcodes port 2000).

The busy-loop output described above is UNVERIFIED — no compile or run was performed in the session that filed this issue. The discarded return values and the absent listening reset are source-verifiable; the observed flood is inferred from them.

Proposed change

The bind failure should stop startup rather than being swallowed: either the constructor refuses to leave a half-built server, or start() declines to loop when no socket was bound. A failed createNewServerThread() should not be ignored indefinitely.


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