GeezerVison is showing github.com — ChannelBufferInput blocks until full buffer is read · Issue #426 · msgpack/msgpack-java
ChannelBufferInput blocks until full buffer is read #426
Description
Please take a look at this sample:
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.msgpack.core.MessagePack;
import org.msgpack.core.MessageUnpacker;
public class ChannelUnpackerTest {
public static void main(String[] args) throws Exception {
try (ServerSocketChannel serverChannel = ServerSocketChannel.open()) {
serverChannel.socket().bind(new InetSocketAddress("localhost", 7777));
ExecutorService pool = Executors.newFixedThreadPool(10);
for (int i = 0; i < 10; i++) {
pool.execute(() -> {
try {
SocketChannel channel = serverChannel.accept();
channel.write(ByteBuffer.wrap(new byte[200]));
} catch (Exception e) {
//nothing
}
});
}
try (Socket socket = new Socket("localhost", 7777)) {
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(socket.getInputStream());
unpacker.readPayload(ByteBuffer.allocate(128));
System.out.println("read from socket");
}
try (SocketChannel channel = SocketChannel.open(new InetSocketAddress("localhost", 7777))) {
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(channel);
unpacker.readPayload(ByteBuffer.allocate(128));
System.out.println("read from channel");
}
}
}
}
This sample accepts incoming connection, writes 200 bytes to it and waits indefinitely. Consuming first 128 (that is from my real use case - after establishing connection I need to read servers hello message with fixed size of 128 bytes) via MessageUnpacker created via socket InputStream handles this case just fine, however via SocketCnahhel it blocks.
Changing the server to write large enough data (e.g. 20000 bytes) leads to filling of MessageUnpackers buffer and it can return first 128 bytes.
Activity
komamitsu commented on Jun 22, 2017
@isopov Thanks for the reporting.
It seems a bug of ChannelBufferInput#next. I'll handle it at #428.
We need to write more tests of ChannelBufferInput and so on...
komamitsu commented on Jul 11, 2017
Metadata
Metadata
Development
No branches or pull requestsIssue actions