0

I am implementing a middleware between clients of the memaslapbenchmark and the memcachedserver. The key size is set to 16Bytes and the value size to 1024Bytes, so the request should never exceed 2048Bytes which is MAX_PACKET_LENGTH in the following code fragment:

ByteBuffer buffer = ByteBuffer.allocate(MAX_PACKET_LENGTH);

while(running) {
    try {
        buffer.clear();
        socketChannel.read(buffer);
    } catch (IOException e) {
        e.printStackTrace();
    }
    ....
}

It is very strange to me why after a certain amount of requests (it is never the same amount) there occurs a BufferOverflow despite I did a buffer.clear() before.

Can anyone help me?

Samuel Kok
  • 585
  • 8
  • 16
Dr3w Br1ck13
  • 187
  • 1
  • 5
  • 14
  • What line / method is throwing the exception? `SocketChannel.read()` never tries to read more data than would fit in the buffer, so it will not throw a `BufferOverflowException`. One way I imagine it might happen is if you are modifying the buffer from another thread while `SocketChannel.read()` is being executed. – Jesper Sep 30 '16 at 08:01
  • @Jesper you were right. There are other threads which are modifying the buffer. Sending a duplicate to the other thread solved the problem. thx – Dr3w Br1ck13 Sep 30 '16 at 08:12

0 Answers0