You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "lbh6771740 (via GitHub)" <gi...@apache.org> on 2023/06/02 02:18:27 UTC

[GitHub] [dubbo] lbh6771740 opened a new issue, #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

lbh6771740 opened a new issue, #12434:
URL: https://github.com/apache/dubbo/issues/12434

   您好,我想咨询下使用dubbo triple reactor 方式通信的程序,当调用方程序被杀死停止后,为什么服务提供方建立的流doFinally方法不会收到中断信号? 我理想的情况是服务提供方建立的流doFinally方法应该收到中断信号,这样我程序可以做一些资源清理操作,但目前实际程序运行并没有,希望能解答下,谢谢!
   
   环境:
   dubbo :3.1.5
   protobuf-java: 3.22.0
   
   
   rpc.proto文件:
   ```
   syntax = "proto3";
   
   option java_multiple_files = true;
   
   package com.protocol.grpc;
   
   message Request {
     int64 id = 1;
     string sessionId = 2;
     string userId = 3;
     string ns = 4;
     string cmd = 5;
     bool binary = 6;
     bytes payload = 7;
   }
   
   enum ResponseType {
     RESPONSE = 0;
     PUSH = 1;
   }
   
   message Response {
     int64 id = 1;
     string sessionId = 2;
     string userId = 3;
     string ns = 4;
     string cmd = 5;
     bool binary = 6;
     bytes payload = 7;
     bool success = 8;
     string msg = 9;
     ResponseType type = 10;
   }
   
   service DataModelService {
     rpc connect(stream Request) returns (stream Response);
   }
   
   ```
   
   
   下面是简单的提供方代码,通过connect建立连接后,收到消息就原样返回。
   
   ```
   @Slf4j
   @DubboService(group = "test-sse")
   @RequiredArgsConstructor
   public class SseDataModelServiceProvider extends DubboDataModelServiceTriple.DataModelServiceImplBase {
   
   	@Override
   	public Flux<Response> connect(Flux<Request> request) {
   		return request.doFinally(signalType -> {
   			log.info("connect is finally, signalType:{}", signalType);
   
   			//TODO
   			//做一些资源回收
   
   		}).doOnNext(requestMsg -> {
   			log.info("get data: {}", requestMsg);
   		}).flatMap(requestMsg -> Flux.just(Response
   						.newBuilder()
   						.setId(requestMsg.getId())
   						.setSessionId(requestMsg.getSessionId())
   						.setUserId(requestMsg.getUserId())
   						.setBinary(requestMsg.getBinary())
   						.setType(ResponseType.RESPONSE)
   						.setCmd(requestMsg.getCmd())
   						.setNs(requestMsg.getNs())
   						.setSuccess(true)
   						.setPayload(ByteString.copyFrom(("payload").getBytes(StandardCharsets.UTF_8))).build())
   				);
   	}
   }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] lbh6771740 commented on issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

Posted by "lbh6771740 (via GitHub)" <gi...@apache.org>.
lbh6771740 commented on issue #12434:
URL: https://github.com/apache/dubbo/issues/12434#issuecomment-1569735593

   接上面的问题,补全一下调用方的代码和相关环境。
   spring-boot:2.7.7
   zookeeper:3.5.10
   
   
   简单的调用方代码,使用Flux.interval定时持续发送消息,代码如下:
   ```
   @Slf4j
   @SpringBootApplication
   @Service
   @EnableDubbo
   public class ConsumerApplicationMain {
   
       @DubboReference(proxy = "nativestub", group = "test-sse")
       DataModelService dataModelService;
       
   
       public static void main(String[] args) {
           ConfigurableApplicationContext applicationContext = SpringApplication.run(ConsumerApplicationMain.class, args);
           ConsumerApplicationMain bean = applicationContext.getBean(ConsumerApplicationMain.class);
          
           //调用方定时持续发送消息
           bean.dataModelService.connect(Flux.interval(Duration.ofSeconds(1)).map(num-> {
                               var builder = Request.newBuilder();
                               builder.setId(num);
                               builder.setSessionId("sessionId"+num);
                               builder.setUserId("userId"+num);
                               builder.setNs("ns"+num);
                               builder.setCmd("cmd"+num);
                               builder.setPayload(ByteString.copyFrom(("payload"+num).getBytes(StandardCharsets.UTF_8)));
                               builder.setBinary(false);
                               return  builder.build();
                           }))
                   .subscribe(System.out::println);
   
   
   
   
          new Scanner(System.in).nextLine();
       }
   }
   ```
   
   当提供方和调用方启动成功后,连通正常会收发消息。 此时我停止掉调用方(无论是使用kill还是kill -9 强制杀死),提供方的doFinally方法都收不到流的中断信号,导致我这边无法做资源回收清理动作。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] lbh6771740 closed issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

Posted by "lbh6771740 (via GitHub)" <gi...@apache.org>.
lbh6771740 closed issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?
URL: https://github.com/apache/dubbo/issues/12434


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] lbh6771740 commented on issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

Posted by "lbh6771740 (via GitHub)" <gi...@apache.org>.
lbh6771740 commented on issue #12434:
URL: https://github.com/apache/dubbo/issues/12434#issuecomment-1571591224

   @icodening 谢谢您的答复,但针对这个回答不是很满意,因为它需要使用者做额外的开发工作(我理解框架自身应该赋予该能力,在底层tcp断连后,对流做一些特殊处理),并且调用方的jvm钩子回调不一定能精确执行到,可能因某些外部原因强制停止了服务,根本就没有机会去执行钩子回调。  
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] icodening commented on issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

Posted by "icodening (via GitHub)" <gi...@apache.org>.
icodening commented on issue #12434:
URL: https://github.com/apache/dubbo/issues/12434#issuecomment-1571520669

   @lbh6771740 
   因为调用方使用 `Flux.interval` 方式且没有明确调用停止流的操作符,而`kill`并不会主动调用结束操作符,所以Provider这边是收不到结束信号的.    可以在调用方注册一个JVM钩子回调,手动结束流


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] lbh6771740 commented on issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

Posted by "lbh6771740 (via GitHub)" <gi...@apache.org>.
lbh6771740 commented on issue #12434:
URL: https://github.com/apache/dubbo/issues/12434#issuecomment-1573036972

   @icodening 我做了实验,Google原生grpc框架,就可以做到调用方停止后,服务提供方的流会触发doFinally方法,对应的中断类型是cancle。我猜测应该是dubbo框架暂时对stream流功能还不够完善,后期应该会处理这个问题。 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] lbh6771740 commented on issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

Posted by "lbh6771740 (via GitHub)" <gi...@apache.org>.
lbh6771740 commented on issue #12434:
URL: https://github.com/apache/dubbo/issues/12434#issuecomment-1575951730

   @icodening 大佬优秀,坐等合并使用最新的版本,那我这边应该可以关闭这个问题了,谢谢


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] lbh6771740 commented on issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

Posted by "lbh6771740 (via GitHub)" <gi...@apache.org>.
lbh6771740 commented on issue #12434:
URL: https://github.com/apache/dubbo/issues/12434#issuecomment-1571846039

   
   @icodening 嗯,您说的我理解,框架也可以在tcp断开后,给我发送error指令也可以的。我只是个人理解框架做更合适,可能我的想法比较肤浅。但是目前我使用该框架建立了流连接,现在调用方停掉了,服务提供方该如何去合理的针对这个不可用的流产生的资源进行回收,我需要一个安全可靠的解决方案。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] lbh6771740 closed issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

Posted by "lbh6771740 (via GitHub)" <gi...@apache.org>.
lbh6771740 closed issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?
URL: https://github.com/apache/dubbo/issues/12434


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] icodening commented on issue #12434: 使用dubbo triple reactor 方式通信,当调用方程序被杀死停止后,服务提供方建立的流doFinally方法不会收到中断信号?

Posted by "icodening (via GitHub)" <gi...@apache.org>.
icodening commented on issue #12434:
URL: https://github.com/apache/dubbo/issues/12434#issuecomment-1571765649

   @lbh6771740 
   让框架层面来做结束操作似乎不合理,框架无法预知在Streaming下用户的停机行为,不应该自动发送complete指令吧


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org