'Socket closed' by the server when running tests

Hello there,

we have an Implementation for the client side of the WebSocket protocol as described in RFC 6455.

We test this implementation using the autobahn suite crossbario/autobahn-testsuite:0.8.2. We tested it locally using the docker image (executing docker pull crossbario/autobahn-testsuite:0.8.2).

How do we test:

  1. We start the fuzzy server
  2. Our test setup asks from the fuzzy server all possible tests (with some exceptions), and then connects to them one by one, using the appropriate resource when connecting to execute the test.

Here is our issue:
While testing it sometimes happens that the server sends an error saying “Socket closed”. This of course causes the test to fail.
It seems to happen especially with the tests of the “family” 5.X, meaning 5.1, 5.2, etc.

It also happens in an indeterministic way, at least I have no found a pattern yet.

Have you seen a similiar problem before? Why would the server close the socket / connection, suddenly?

Thanks in advance for your help,


I’m writing tests to test the health of the server and client-side. In the test, I run the client-side, through the creation of the socket, on port 3000. And ServerSocket I also specify port 3000. With normal deployment, everything works correctly. But the test falls apart

java.net.SocketException: Socket closed

at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.net.SocketInputStream.read(SocketInputStream.java:224)
at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:337)
at java.io.DataInputStream.readUTF(DataInputStream.java:589)
at java.io.DataInputStream.readUTF(DataInputStream.java:564)
at com.epam.preproduction.linnyk.server.factory.TCPServerTest.testGetCount(TCPServerTest.java:54)

Basically, I have used this type of server fr one of my projects best small business hr checklist and related things.
My Server:

public abstract class Server implements Runnable {
    protected ServerCommand serverCommandController;

    private final Socket clientSocket;

    public Server(Socket clientSocket) {
        this.clientSocket = clientSocket;
        serverCommandController = ApplicationContext.getServerCommandController();
    public void run() {
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                 BufferedWriter output = new BufferedWriter(new PrintWriter(clientSocket.getOutputStream()))) {
                checkPortAndConnection(reader, output);
            } catch (IOException e) {
            } finally {
                try {
                    if (!clientSocket.isConnected()) {
                } catch (IOException e) {

public class TCPServer extends Server {

    public TCPServer(Socket clientSocket) {

    protected String getRequest(BufferedReader input) throws IOException {
        return input.readLine();

    protected void setResponse(BufferedWriter output, String request) throws IOException {
        String result = serverCommandController.execute(RequestParser.tcpParserCommand(request));
        output.write(result + "\n");


    public class TCPServerTest {

    private static StoreService productService;
    private static Server serverSide;
    private static Socket socket;

    private static DataInputStream ois;
    private static DataOutputStream oos;

    public static void init() throws IOException {
        Main main = new Main();
        productService = new StoreServiceImpl(new ProductRepositoryImpl());
        socket = new Socket(InetAddress.getLocalHost(), 3000);
        Runnable server = () -> {
            serverSide = new TCPServer(socket);
            try {
            } catch (Throwable throwable) {
        new Thread(server).start();
        ois = new DataInputStream(socket.getInputStream());
        oos = new DataOutputStream(socket.getOutputStream());

    public void testGetCount() throws IOException {
        oos.writeUTF("get count");
        String response = ois.readUTF();
        int count = productService.getProductMap().size();
        String expectedCount = String.valueOf(count);
        assertEquals(expectedCount, response);

    public static void tearDown() throws IOException {

I do not understand a bit where I could make a mistake. Can you tell me where the error in the test is? Thank you in advance)

Found an error that in this method to my request is added oos.writeUTF("get count"); /t how can it be removed?