pSpaces / jSpace

Programming with Spaces in Java
MIT License
17 stars 12 forks source link

SocketException in SpaceRepository addHandler method #17

Closed Groenbech96 closed 6 years ago

Groenbech96 commented 6 years ago

In the code from the SpaceRepository I have come across some missing error handling...

private void addHandler(ClientHandler handler) {
        executor.execute(() -> {
            while (handler.isActive()) {
                ClientMessage message;
                try {
                    message = handler.receive();
                    if (message != null) {
                        handler.send(handle(message));                  
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    message = null;
                                        // This IOException
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    message = null;
                }
            }
            try {
                handler.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }

The SocketException is thrown if I forcefully close one part of an active connection. This of course disrupts the connection and the IOExceotion is thrown and caught in the code above, but this creates an endless while loop, due to the handler.isActive() never becoming inactive, and thus the whole application crashes.

I tried to put a return statement after the e.printStackTrace, and this stopped the application from crashing.

michele-loreti commented 6 years ago

This has been fixed with the last commits.