1 year ago

#388560

test-img

cool_ravi

Request stuck when multipart streaming enable in webflux

I'm trying to forward the multipart data to another API. I'm successfully able to do it.

2022-04-07 22:26:06,822 LL="INFO"  TR="loopClient-nio-3" LN="com.example.demo.MainController"    Content Type of this request multipart/form-data;boundary=--------------------------011142320810236414887622
2022-04-07 22:26:06,822 LL="INFO"  TR="loopClient-nio-3" LN="reactor.Mono.MapFuseable.2"    | onSubscribe([Fuseable] FluxMapFuseable.MapFuseableSubscriber)
2022-04-07 22:26:06,822 LL="INFO"  TR="loopClient-nio-3" LN="reactor.Mono.MapFuseable.2"    | request(unbounded)
2022-04-07 22:26:06,825 LL="INFO"  TR="loopClient-nio-3" LN="reactor.Mono.MapFuseable.2"    | onNext({res3=[DefaultFormFieldPart{res3}], res2=[DefaultFilePart{res2 (test.txt)}]})
2022-04-07 22:26:06,825 LL="INFO"  TR="loopClient-nio-3" LN="com.example.demo.MainController"    Total size 2
2022-04-07 22:26:06,825 LL="INFO"  TR="loopClient-nio-3" LN="com.example.demo.MainController"    FormFieldPart: res3
2022-04-07 22:26:06,825 LL="INFO"  TR="loopClient-nio-3" LN="com.example.demo.MainController"    FilePart: res2
2022-04-07 22:26:06,831 LL="INFO"  TR="loopClient-nio-3" LN="reactor.Mono.MapFuseable.2"    | onComplete()

However, by default, DefaultPartHttpMessageReader.setStreaming is false. Therefore, this multipart data would get saved on disk or in-memory. And, to avoid getting it saved on disk, I have following configuration for my application to enable streaming

@Configuration
@EnableWebFlux
public class WebConfig implements WebFluxConfigurer {

  @Override
  public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
    configurer.defaultCodecs().multipartReader(new MultipartHttpMessageReader(defaultPartHttpMessageReader()));

  }
  
  public DefaultPartHttpMessageReader defaultPartHttpMessageReader() {
      DefaultPartHttpMessageReader defaultPartHttpMessageReader = new DefaultPartHttpMessageReader();
      defaultPartHttpMessageReader.setStreaming(true);
      return defaultPartHttpMessageReader;
  }
}

But, when I enable it, I see request consist file get stuck while upload and could see following logs

2022-04-07 22:23:27,109 LL="INFO"  TR="loopClient-nio-3" LN="com.example.demo.MainController"    Content Type of this request multipart/form-data;boundary=--------------------------227791809638103619563128
2022-04-07 22:23:27,126 LL="INFO"  TR="loopClient-nio-3" LN="reactor.Mono.MapFuseable.1"    | onSubscribe([Fuseable] FluxMapFuseable.MapFuseableSubscriber)
2022-04-07 22:23:27,128 LL="INFO"  TR="loopClient-nio-3" LN="reactor.Mono.MapFuseable.1"    | request(unbounded)

Comparing working scenario, could see onNext is not getting called, which is causing request to stuck.

Could anyone share thoughts, what is it I'm missing here ?

java

spring

spring-webflux

multipartform-data

project-reactor

0 Answers

Your Answer

Accepted video resources