[WebFlux] 由于没有处理Netty HTTP表体导致的问题

[WebFlux] 由于没有处理Netty HTTP表体导致的问题

  • 场景一
  • 场景二
  • 遗留问题

HTTP请求有表体,但是WebFlux应用没有获取表体内容并进行处理。接下来

场景一

环境部署:Postman -> Nginx -> WebFlux Server
问题:通过Postman发送包含表体的请求时,会经常出现无返回的情形,经查Nginx端出现错误

2019/12/06 12:08:30 [error] 395614#0: *222 readv() failed (104: Connection reset by peer) while reading upstream, client: 172.20.17.75, server: gwdemo.to.com, request: “GET /game/animal/get HTTP/1.1”, upstream: “http://127.0.0.1:1601/game/animal/get”, host: “gwdemo.to.com”

通过拿掉 Nginx 或 修改nginx配置关闭缓存可解决

proxy_buffering off;

具体原因不明!

场景二

环境部署: Postman -> Nginx-1 -> Spring Cloud Gateway -> Nginx-2 -> WebFlux Server
问题:通过Postman发送包含表体请求时,返回错误信息,经查

Nginx1 错误

2019/12/06 13:57:05 [error] 418274#0: *388169 upstream prematurely closed connection while reading response header from upstream, client: 172.17.54.60, server: gw.to.com, request: “GET /demo/game/animal/get HTTP/1.1”, upstream: “http://127.0.0.1:1601/demo/game/animal/get”, host: “gw.to.com”

Spring Cloud Gateway 错误

2019-12-06 12:08:29.840 ERROR 417902 --- [reactor-http-epoll-48] a.w.r.e.AbstractErrorWebExceptionHandler : [6729ed7b] 500 Server Error for HTTP GET "/demo/game/animal/get"

reactor.netty.http.client.PrematureCloseException: Connection prematurely closed DURING response
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Assembly trace from producer [reactor.core.publisher.FluxMap] :
	reactor.core.publisher.Flux.map(Flux.java:5734)
	reactor.netty.ByteBufFlux.fromInbound(ByteBufFlux.java:70)
Error has been observed by the following operator(s):
	|_	Flux.map ⇢ reactor.netty.ByteBufFlux.fromInbound(ByteBufFlux.java:70)
	|_	Flux.doOnNext ⇢ reactor.netty.ByteBufFlux.retain(ByteBufFlux.java:298)
	|_	Flux.map ⇢ org.springframework.cloud.gateway.filter.NettyWriteResponseFilter.lambda$filter$1(NettyWriteResponseFilter.java:89)
	|_	Mono.doOnError ⇢ 

遗留问题

虽然最终通过接收并处理 HTTP请求体 解决了上述问题,但具体是什么原因导致连接提前关闭至今没有找到答案,同志仍需努力啊!

你可能感兴趣的:(Spring,WebFlux)