Closed jonhkr closed 7 years ago
These are the dependencies:
compile 'org.projectlombok:lombok:1.16.16'
compile 'io.reactivex:rxnetty-tcp:0.5.2'
ByteBuf
s are stored off-heap by default and need to be manually released. You're leak is at:
c.getInput()
.map(bb -> bb.toString(Charset.defaultCharset()))
.subscribe(m -> events.event(c.unsafeNettyChannel().remoteAddress().toString(), m));
You can use #autoRelease()
to free up the memory automatically
c.getInput().autoRelease()
.map(bb -> bb.toString(Charset.defaultCharset()))
.subscribe(m -> events.event(c.unsafeNettyChannel().remoteAddress().toString(), m));
You may also want to look at RxJavaString to re-frame incoming events in case a message is broken across two TCP frames (in particular #split(...) and #byLine()). This would look like:
c.getInput().autoRelease()
.map(bb -> bb.toString(Charset.defaultCharset()))
.compose(StringObservable::byLine)
.subscribe(m -> events.event(c.unsafeNettyChannel().remoteAddress().toString(), m));
Thank you @jamesgorman2 for the quick reply.
The #autoRelease()
method did the trick. 😃
np @jonhkr been there, done that when I was learning this :-)
I'm testing
RxNetty
and got the following log message:The implementation is as follows:
It is a simple chat application, every message received is broadcasted to everyone connected to the server.
I'm using tcpkali (https://github.com/machinezone/tcpkali) to make requests to the server and I get that error when I run the following command:
You can see messages coming by running:
Am I doing something wrong or is that a bug in
RxNetty
?