Skip to content

Conversation

@stevegury
Copy link
Member

Problem
There's a memory leak in ReactiveSocketServerHandler, it keep adding entries
in the duplexConnections map but never remove them.

Solution
Instead of having only one ReactiveSocketServerHandler, and manage resources
manually, we let Netty allocate one instance per Channel. Then no resource
management is necessary.

Modifications
I refactored all the uages of ReactiveSocketServerHandler whithout changing
the logic. I also got rid of the method

public void channelReadComplete(ChannelHandlerContext ctx) {
    ctx.flush();
}

since we only use writeAndFlush in the DuplexConnection (we're sure there's
nothing to flush).

** Problem **
There's a memory leak in `ReactiveSocketServerHandler`, it keep adding entries
in the `duplexConnections` map but never remove them.

** Solution **
Instead of having only one `ReactiveSocketServerHandler`, and manage resources
manually, we let Netty allocate one instance per Channel. Then no resource
management is necessary.

** Modifications **
I refactored all the uage of `ReactiveSocketServerHandler` whithout changing
the logic. I also got rid of the method
```
public void channelReadComplete(ChannelHandlerContext ctx) {
    ctx.flush();
}
```
since we only use `writeAndFlush` in the DuplexConnection (we're sure there's
nothing to flush).
ctx.name(),
LengthFieldBasedFrameDecoder.class.getName(),
new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE >> 1, 0, BitUtil.SIZE_OF_INT, -1 * BitUtil.SIZE_OF_INT, 0));
LengthFieldBasedFrameDecoder frameDecoder =
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: It doesn't make much of a difference but we can move this to server initialization i.e. add these handlers upfront using ChannelInitializer instead of doing it on handlerAdded

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, we'll improve that later.

@NiteshKant
Copy link
Contributor

👍 I will merge this change, my minor comment can be addressed later.

@NiteshKant NiteshKant merged commit 691e044 into master Jun 16, 2016
@stevegury stevegury deleted the stevegury/fix-netty-channel-handler branch July 15, 2016 22:32
ilayaperumalg pushed a commit to ilayaperumalg/rsocket-java that referenced this pull request Dec 26, 2017
Fixes rsocket#94 (Protocol Status)

As discussed in the issue, this change specifies a status of the protocol as draft.
This also elaborates on the versioning scheme used for the protocol and how to specify the same in the SETUP frame.
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.

3 participants