GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

New issue
Copy link
New issue
Copy link
Closed
Closed
ChannelBufferInput blocks until full buffer is read#426
Copy link

Description

@isopov
isopov
opened on Jun 20, 2017
Issue body actions

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

  1. komamitsu commented on Jun 22, 2017

    @komamitsu
    komamitsu
    on Jun 22, 2017
    Member
    More actions

    @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...

  2. komamitsu commented on Jul 11, 2017

    @komamitsu
    komamitsu
    on Jul 11, 2017
    Member
    More actions

    #428 is merged

  3. komamitsu
    closed this as completedon Jul 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.