benedekh / WeLoveClouds

Repository for submissions on the CloudDB course.
0 stars 1 forks source link

Memory leak in CommunicationService.receive method #108

Closed benedekh closed 7 years ago

benedekh commented 7 years ago

weloveclouds.communication.services.CommunicationService.receive()

if (connectionToEndpoint.isConnected()) {
            byte[] receivedData = null;

            InputStream socketDataReader = **connectionToEndpoint**.getInputStream();

            **while (receivedData == null) {**
                int availableBytes = socketDataReader.available();
                if (availableBytes != 0) {
                    LOGGER.debug(CustomStringJoiner.join(" ", "Receiving",
                            String.valueOf(availableBytes), "from the connection."));
                    receivedData = new byte[availableBytes];
                    socketDataReader.read(receivedData);
                    LOGGER.debug("Data received from the network.");
                }
            }
            return receivedData;
        }

The while loop never exits even though the referred socket may be already closed from the other (client) side.

benedekh commented 7 years ago

fixed by #110