spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Memory Leak in WebFlux application handling HTTP Multipart

Open bugs84 opened this issue 1 year ago • 0 comments

Version spring-boot version 3.3.1 spring-webflux 6.1.10

Description In one of our applications, we are facing OutOfMemory error. We think, that it is connected with Webflux and the upload files using HTTP Multipart requests.

We managed to create a small project with the test, that is able to reproduce issue: LEAK: ByteBuf.release() was not called before it's garbage-collected.

The project can be found here: https://github.com/bugs84/webflux-leak-02

Basically, there is a controller that accepts multipart and saves it into the files.

   @PostMapping("/upload-files10")
    fun uploadFileWithoutEntity(@RequestPart("files", required = false) filePartFlux: Flux<Part>): Mono<*> {
        return filePartFlux.collectList().flatMap { fileList: List<Part> ->
            Flux.fromIterable(fileList).flatMapSequential { file: Part ->
                val destination = Paths.get("generated_${fileNumber++}.file")
                DataBufferUtils.write(file.content(), destination).then(Mono.just("ok"))
            }.then(Mono.just("OK"))
        }
    }

If we run the test it should generate the mentioned LEAK: issue.

bugs84 avatar Jun 25 '24 11:06 bugs84