当使用Pub/Sub停止服务并在Google上运行时,将收到以下堆栈跟踪。
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容器的方式有关?只有捕获异常才不是令人满意的解决方案,因为我们可能会让处理过的消息不被确认。我们能以任何方式解决这个问题吗?这样我们就可以安全地停止我们的服务了吗?
提前谢谢。
发布于 2018-06-12 08:47:10
我发现错误在我的代码里..。我正在ASP.NET核心中使用ASP.NET,并通过以下方法停止订阅者:
cancellationToken.Register(async () => { await subscriber.StopAsync(token) })
但是,这将触发和忘记,因此不会等待客户端在处理服务提供程序中的对象之前正确停止。由于我使用Google.Cloud.Diagnostics.AspNetCore (在服务提供者中注册并使用Grpc)记录一些有用的调试语句,因此可以在结束使用之前对其进行处理。
https://stackoverflow.com/questions/50666215
复制相似问题