The original report can in https://github.com/reactor/reactor-netty/issues/1546. The scenario is an SSE endpoint with a reactive repository (MongoDB) but the use of the repository is not related or at least a leak can be demonstrated without it.
Using a controller like this:
@GetMapping(path = "/cars", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Car> getCar() {
return Flux.interval(Duration.ofMillis(50))
.map(aLong -> new Car(aLong, gen.location()))
.onBackpressureDrop();
}
and a script like this:
for i in {1..100}; do ../../../tmp/wrk/wrk -t2 -c 100 -d 2s --latency http://localhost:8080/cars; done
I get a leak record that points to the `ServerSentEventHttpMessageWriter:
Recent access records:
Created at:
io.netty.buffer.AbstractByteBufAllocator.compositeDirectBuffer(AbstractByteBufAllocator.java:223)
io.netty.buffer.AbstractByteBufAllocator.compositeBuffer(AbstractByteBufAllocator.java:201)
org.springframework.core.io.buffer.NettyDataBufferFactory.join(NettyDataBufferFactory.java:108)
org.springframework.http.codec.ServerSentEventHttpMessageWriter.encodeEvent(ServerSentEventHttpMessageWriter.java:176)
org.springframework.http.codec.ServerSentEventHttpMessageWriter.lambda$encode$0(ServerSentEventHttpMessageWriter.java:160)
Comment From: rstoyanchev
@ramiloif I've committed a fix for this issue. Would you be able to try Spring Framework 5.3.6-SNAPSHOT
?
Comment From: rstoyanchev
It looks like a fix went into 5.3.6 but the issue wasn't assigned a milestone.