首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Grpc System.ObjectDisposedException:安全句柄已关闭

Grpc System.ObjectDisposedException:安全句柄已关闭
EN

Stack Overflow用户
提问于 2018-06-03 12:06:43
回答 1查看 989关注 0票数 2

当使用Pub/Sub停止服务并在Google上运行时,将收到以下堆栈跟踪。

代码语言:javascript
运行
复制
System.ObjectDisposedException: Safe handle has been closed
    at System.Runtime.InteropServices.SafeHandle.DangerousAddRef
    at System.StubHelpers.StubHelpers.SafeHandleAddRef
    at Grpc.Core.Internal.ChannelSafeHandle.CreateCall
    at Grpc.Core.Internal.AsyncCall`2.CreateNativeCall
    at Grpc.Core.Internal.AsyncCall`2.Initialize
    at Grpc.Core.Internal.AsyncCall`2.StartDuplexStreamingCall
    at Grpc.Core.Calls.AsyncDuplexStreamingCall[TRequest,TResponse]
    at Grpc.Core.DefaultCallInvoker.AsyncDuplexStreamingCall[TRequest,TResponse]
    at Grpc.Core.Internal.InterceptingCallInvoker.AsyncDuplexStreamingCall[TRequest,TResponse]
    at Google.Cloud.PubSub.V1.Subscriber.SubscriberClient.StreamingPull
    at Google.Api.Gax.Grpc.ApiBidirectionalStreamingCall.<>c__DisplayClass0_0`2.<Create>b__0
    at Google.Api.Gax.Grpc.ApiBidirectionalStreamingCall`2.Call
    at Google.Cloud.PubSub.V1.SubscriberServiceApiClientImpl.StreamingPull
    at Google.Cloud.PubSub.V1.SubscriberClientImpl.SingleChannel.<StartAsync>d__18.MoveNext

对于该项目,我们使用ASP.NET Core和库来处理Pub/Sub通信。使用Pub/Sub仿真器在本地调试时不存在此问题。因此,我们假设它与App逐步淘汰docker容器的方式有关?只有捕获异常才不是令人满意的解决方案,因为我们可能会让处理过的消息不被确认。我们能以任何方式解决这个问题吗?这样我们就可以安全地停止我们的服务了吗?

提前谢谢。

EN

Stack Overflow用户

发布于 2018-06-12 08:47:10

我发现错误在我的代码里..。我正在ASP.NET核心中使用ASP.NET,并通过以下方法停止订阅者:

cancellationToken.Register(async () => { await subscriber.StopAsync(token) })

但是,这将触发和忘记,因此不会等待客户端在处理服务提供程序中的对象之前正确停止。由于我使用Google.Cloud.Diagnostics.AspNetCore (在服务提供者中注册并使用Grpc)记录一些有用的调试语句,因此可以在结束使用之前对其进行处理。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50666215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档