问题描述
生产代码报错:
2022-10-31T09:06:46,530 [portRiskService-1002-2950@168-63-70-238:8] ERROR io.grpc.internal.ManagedChannelOrphanWrapper - *~*~*~ Channel ManagedChannelImpl{logId=7, target=168.63.18.186:50057} was not shutdown properly!!! ~*~*~* Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true. java.lang.RuntimeException: ManagedChannel allocation site at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init>(ManagedChannelOrphanWrapper.java:93) at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:53) at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:44) at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:596) at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:261) at com.huatai.quant.history.request.RiskReqHandler.<init>(RiskReqHandler.java:100) at com.huatai.quant.service.PortRiskNatsService.riskReqHandler(PortRiskNatsService.java:453) at com.huatai.nats.api.impl.client.Client.lambda$subscribe$0(Client.java:306) at io.nats.client.impl.NatsDispatcher.run(NatsDispatcher.java:98) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
源码:
每来一个请求,都会new一个这个RiskReqHandler,那么每次都会新建这样一个channel
解决方案(可能的)
注意:该方案并没有实践验证,只是理论
每次用完channel后,手动shutdown。
shutdown()是初始化一个“秩序井然”的关闭操作 -- 意味着当前已经存在的调用preexisting call会继续,担心新调用new call会被立刻取消
参考文献
Channel ManagedChannelImpl was not shut down properly:https://stackoverflow.com/questions/57481760/channel-managedchannelimpl-was-not-shut-down-properly#
GRPC简介:https://www.cnblogs.com/resentment/p/6714610.html
标签:shut,java,gRPC,down,ManagedChannelOrphanWrapper,internal,io,com,grpc From: https://www.cnblogs.com/frankcui/p/16844105.html