Skip to content

ephemeral port#293

Merged
yschimke merged 7 commits into
rsocket:1.0.xfrom
yschimke:ephemeral_port
May 31, 2017
Merged

ephemeral port#293
yschimke merged 7 commits into
rsocket:1.0.xfrom
yschimke:ephemeral_port

Conversation

@yschimke

@yschimke yschimke commented May 26, 2017

Copy link
Copy Markdown
Member

Allow TCP server to use an ephemeral port

@yschimke yschimke requested review from rdegnan and robertroeser May 26, 2017 14:54
return RSocketFactory
.connect()
.transport(TcpClientTransport.create("localhost", 8000))
.transport(TcpClientTransport.create(address.getHostString(), address.getPort()))

@yschimke yschimke May 26, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am considering adding TcpClientTransport.create(InetSocketAddress) here

@yschimke

Copy link
Copy Markdown
Member Author

cc @phoad

.receive()
.acceptor((setup, sendingSocket) -> Mono.just(new RSocketProxy(handler)))
.transport(TcpServerTransport.create("localhost", 8000))
.transport(serverTransport)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally server would be a better type than Closeable, then I could get address off that.

RSocket client = buildClient();

// TODO without this failure is always a timeout
Thread.sleep(1000);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

return out.neverComplete();
});

serverMono.map(s -> s.address()).subscribe(address);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we provide port value of "0", each time we call start(), it generates a new NettyContext, which has a different "address" - "port" value. So if the caller first calls start(..) and then asks for the "address" value, while another caller also calls start(..) and asks for the address value, then there will be a race condition. Other than that, when we call start(..) at the inside of a single thread, the address value of the initial call will be lost.

It seems we only need the "address" if we pass port value of "0", otherwise address can be created by merging "bindAddress" and "port"? If so, we might have a overload method which also provides the address value back? If caller really needs the address back, the caller can call this overloaded one. So we will not need any class member and it will still be ok for multithreading?

@yschimke yschimke May 28, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't considered that you would reuse a TcpServerTransport. It seems problematic to do so as the code currently stands as you either

  1. use a static port and clients are responsible for remembering the state e.g. is there an open server port? The start call will fail unless a client has called closed.
  2. use a free port (0) and then multiple calls to start work but with the race condition and address() is on the wrong class.

Overall this makes me think my original comment in the PR is correct "Alternatively we can make sure that server is a better type than Closeable." So this start method should return something more useful than Closeable (representing the server, not a single connection).

@phoad phoad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

})
.map(NettyContextClosable::new);
}
.newHandler((in, out) -> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - indentation change.

@yschimke yschimke merged commit 5d173aa into rsocket:1.0.x May 31, 2017
@yschimke yschimke deleted the ephemeral_port branch May 31, 2017 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants