简体   繁体   English

如何处理 reactor-netty 在 spring-webflux 中终止请求?

[英]How to handle reactor-netty terminating a request in spring-webflux?

We have a spring-webflux application running on spring-boot-starter-webflux:jar:2.1.5.RELEASE and reactor-netty:jar:0.8.8.RELEASE .我们有一个在spring-boot-starter-webflux:jar:2.1.5.RELEASEreactor-netty:jar:0.8.8.RELEASE spring-boot-starter-webflux:jar:2.1.5.RELEASE上运行的spring-webflux应用程序。 When a reactive client goes away (k8s pod killed or the client subscription is disposed off) before the request is completed, we see the server simply stops processing the request and no more application logs related to that request are seen.当响应式客户端在请求完成之前消失(k8s pod 被终止或客户端订阅被释放)时,我们看到服务器只是停止处理请求,并且不再看到与该请求相关的应用程序日志。 However, reactive-netty prints a trace log indicating that the channel is inactive and will be terminated.但是, reactive-netty打印一个跟踪日志,指示通道处于非活动状态并将被终止。

Is there anything we can do to handle this termination gracefully?我们可以做些什么来优雅地处理这个终止? We would ideally like to respond to a cancellation signal from reactor.理想情况下,我们希望响应来自反应堆的取消信号。

2020-03-18T16:46:40.372Z TRACE --- [reactor-http-epoll-2] r.n.c.ChannelOperations : [id: 0x4cad974b, L:/<SERVER_IP_ADDRESS>:8080 ! R:/<SOME_OTHER_IP_ADDRESS>:55436] Disposing ChannelOperation from a channel
java.lang.Exception: ChannelOperation terminal stack
    at reactor.netty.channel.ChannelOperations.terminate(ChannelOperations.java:391)
    at reactor.netty.channel.ChannelOperations.onInboundClose(ChannelOperations.java:360)
    at reactor.netty.channel.ChannelOperationsHandler.channelInactive(ChannelOperationsHandler.java:72)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:257)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:243)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:236)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelInactive(CombinedChannelDuplexHandler.java:420)
    at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:393)
    at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:358)
    at io.netty.channel.CombinedChannelDuplexHandler.channelInactive(CombinedChannelDuplexHandler.java:223)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:257)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:243)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:236)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1416)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:257)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:243)
    at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:912)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:816)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:416)
    at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:331)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.base/java.lang.Thread.run(Thread.java:834)

The doOnCancel operator allows for a callback to be provided when a subscription is cancelled. doOnCancel运算符允许在取消订阅时提供回调。 This is different from the doOnEach operator which is run only when the subscription completes or errors out.这与doOnEach运算符不同, doOnEach运算符仅在订阅完成或出错时运行。

https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html#doOnCancel-java.lang.Runnable- https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html#doOnCancel-java.lang.Runnable-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为spring-webflux WebClient配置具有reactor netty的HostnameVerifier - Configure HostnameVerifier with reactor netty for spring-webflux WebClient 使用 spring HATEOAS 和 spring webflux 功能 Web 框架 (reactor.netty) - Using spring HATEOAS with spring webflux Functional Web Framework (reactor-netty) 将 spring-webflux 微服务切换到 http/2 (netty) - Switch spring-webflux microservice to http/2 (netty) 如何在基于Spring-Webflux的REST服务中处理异常 - How to handle exceptions in spring-webflux based REST service Spring Webflux Reactor Netty:HTTP请求/响应十六进制转储? - Spring Webflux Reactor Netty: HTTP Request/Response Hex Dump? 如何在 spring-webflux 中使用请求和会话范围(截至最新版本) - How to use request and session scopes in spring-webflux (as of latest releases) 如何在spring-webflux中获取当前请求的上下文 - How to get the context of the current request in spring-webflux Spring-webflux 过滤器来获取请求体 - Spring-webflux filter to fetch the request body 当服务器提前响应时,Spring WebClient / Reactor-netty 坏了? - Spring WebClient / Reactor-netty broken when a server responds early? 为什么 spring-webflux 应用程序默认运行在 tomcat 而不是 .netty? - Why spring-webflux application is running on tomcat as default, instead of netty?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM