gpt4 book ai didi

How are bidirectional streams handled for TCP disconnection exceptions in gRPC?(在GRPC中如何处理双向流以处理TCP断开连接异常?)

转载 作者:bug小助手 更新时间:2023-10-25 22:05:41 25 4
gpt4 key购买 nike



In a bidirectional streaming setup in gRPC, if one party terminates the TCP connection, for instance, if the server abruptly crashes and restarts, how can the client re-establish the connection? Do we need to handle this manually, or does gRPC itself have mechanisms to address this situation?

在gRPC中的双向流设置中,如果一方终止TCP连接,例如,如果服务器突然崩溃并重新启动,客户端如何重新建立连接?我们需要手动处理这个问题吗?或者gRPC本身有解决这种情况的机制吗?


proto file :

原稿文件:


service LiveService{
rpc Dial(LiveReq)returns(stream LiveResp){}
}

message LiveReq{

}

message LiveResp{
string rtmp = 1;
}

client service:

客户服务:


func handler() {
ctx := context.Background()
req := rpc.LiveReq{}
dial, err := slave.GetLiveClient().Dial(ctx, &req)
if err != nil {
panic(err)
}
for true {

resp, err := dial.Recv() // tcp stop ,server stop
if err != nil {
fmt.Print(err)
}else{
fmt.Print(resp)
}
}
}

how to recover connection?

如何恢复连接?


--------------------------re-edit---------------------------
I did this, check out the link
1.https://github.com/grpc/grpc-go/issues/5507

--------------------------re-edit---------------------------这是我做的,请查看链接1。https://github.com/grpc/grpc-go/issues/5507


更多回答

Does this answer your question? (i.e. the connection will be re-established automatically but it's up to you to re-establish the stream).

这回答了你的问题吗?(即连接将自动重新建立,但重新建立流取决于您)。

@Brits Thanks your reply。I know the TCP re-establishment method, but I want to restore the rpc stream. Can I only execute "slave.GetLiveClient().Dial(ctx, &req)" again, and can't it be automatically restored?

@英国人感谢你的回复。我知道TCP重建方法,但我想恢复RPC流。只能再次执行Slave.GetLiveClient().Dial(ctx,&req),不能自动恢复吗?

Correct - if the stream dies (whether due to a network issue or something else) you need to make an RPC call to re-establish it.

正确-如果流终止(无论是由于网络问题还是其他原因),您需要进行RPC调用以重新建立它。

@Brits look github.com/grpc/grpc-go/issues/5507 and gist.github.com/sosborne1/… . I dit this

@英国人的网站:githorb.com/grpc/grpc-go/Issues/5507和gist.githorb.com/sosborne1/…。我不相信这一点

That just moves the reconnection logic into an Interceptor. This is fine if it achieves your goal; personally I'd rather handle this where the stream is managed because restarting a stream may have unexpected impacts e.g.. loss of data from while the connection was down.

这只是将重新连接逻辑移动到拦截器中。如果它实现了您的目标,这是很好的;就我个人而言,我更愿意在管理流的地方处理这一问题,因为重新启动流可能会产生意想不到的影响。在连接断开时丢失的数据。

优秀答案推荐
更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com