[2017-11-25 15:23:22] [grpc-default-worker-ELG-2-3] [ERROR] [io.netty.handler.codec.http2.DefaultHttp2Connection:181] Caught Throwable from listener onStreamActive.
java.lang.IllegalArgumentException: delay: -846693464887 (expected: >= 0)
at io.netty.util.concurrent.AbstractScheduledEventExecutor.schedule(AbstractScheduledEventExecutor.java:138)
at io.netty.util.concurrent.AbstractScheduledEventExecutor.schedule(AbstractScheduledEventExecutor.java:29)
at io.grpc.internal.KeepAliveManager.onTransportActive(KeepAliveManager.java:202)
at io.grpc.netty.NettyClientHandler$1.onStreamActive(NettyClientHandler.java:211)
at io.netty.handler.codec.http2.DefaultHttp2Connection$ActiveStreams.addToActiveStreams(DefaultHttp2Connection.java:1212)
at io.netty.handler.codec.http2.DefaultHttp2Connection$ActiveStreams.activate(DefaultHttp2Connection.java:1159)
at io.netty.handler.codec.http2.DefaultHttp2Connection$DefaultStream.activate(DefaultHttp2Connection.java:538)
at io.netty.handler.codec.http2.DefaultHttp2Connection$DefaultEndpoint.createStream(DefaultHttp2Connection.java:961)
at io.netty.handler.codec.http2.DefaultHttp2Connection$DefaultEndpoint.createStream(DefaultHttp2Connection.java:868)
at io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder.writeHeaders(DefaultHttp2ConnectionEncoder.java:158)
at io.netty.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders(DecoratingHttp2FrameWriter.java:52)
at io.netty.handler.codec.http2.StreamBufferingEncoder.writeHeaders(StreamBufferingEncoder.java:157)
at io.netty.handler.codec.http2.StreamBufferingEncoder.writeHeaders(StreamBufferingEncoder.java:141)
at io.grpc.netty.NettyClientHandler.createStream(NettyClientHandler.java:426)
at io.grpc.netty.NettyClientHandler.write(NettyClientHandler.java:240)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:739)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:731)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:817)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:724)
at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:1022)
at io.netty.channel.AbstractChannel.write(AbstractChannel.java:291)
at io.grpc.netty.WriteQueue.flush(WriteQueue.java:127)
at io.grpc.netty.WriteQueue.access$000(WriteQueue.java:47)
at io.grpc.netty.WriteQueue$1.run(WriteQueue.java:59)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:445)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:748)
[2017-11-25 15:23:22] [DubboServerHandler-192.170.0.18:20888-thread-179] [ERROR] [org.hyperledger.fabric.sdk.Channel:2241] Sending proposal to peer0.ebaoquan.org failed because of: gRPC failure=Status{code=UNAVAILABLE, description=null, cause=java.io.IOException: 远程主机强迫关闭了一个现有的连接。
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1100)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:367)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:118)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:642)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:565)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:479)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:441)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:748)
}
java.lang.Exception: io.grpc.StatusRuntimeException: UNAVAILABLE
at org.hyperledger.fabric.sdk.Channel.sendProposalToPeers(Channel.java:2241)
at org.hyperledger.fabric.sdk.Channel.sendProposal(Channel.java:2155)
at org.hyperledger.fabric.sdk.Channel.queryBlockByNumber(Channel.java:1680)
at org.mapu.fabric.api.service.client.BcClientService.getBlockInfo(BcClientService.java:132)
at org.mapu.fabric.api.BlockChainApiImpl.getBlockInfo(BlockChainApiImpl.java:117)
at com.alibaba.dubbo.common.bytecode.Wrapper1.invokeMethod(Wrapper1.java)
at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)
at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)
at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
at com.alibaba.dubbo.validation.filter.ValidationFilter.invoke(ValidationFilter.java:57)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:65)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:61)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:132)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:102)
at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:98)
at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170)
at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)
at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:81)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: io.grpc.StatusRuntimeException: UNAVAILABLE
at io.grpc.Status.asRuntimeException(Status.java:540)
at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:439)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426)
at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:76)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:512)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:429)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:544)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:117)
... 3 common frames omitted
然后先研究了下grpc的调用,发现问题出在:
class org.hyperledger.fabric.sdk.EndorserClient
###以下为这个类的要改动的地方,只用看我写的注释的那一部份,huhu
/**
* Construct client for accessing Peer server using the existing channel.
*
* @param channelBuilder The ChannelBuilder to build the endorser client
*/
EndorserClient(ManagedChannelBuilder<?> channelBuilder) {
managedChannel = channelBuilder.build();
//blockingStub = EndorserGrpc.newBlockingStub(managedChannel);//这个没有注释,源码上
//futureStub = EndorserGrpc.newFutureStub(managedChannel);//这个没有注释,源码上
}
public ListenableFuture<FabricProposalResponse.ProposalResponse> sendProposalAsync(FabricProposal.SignedProposal proposal) throws PeerException {
if (shutdown) {
throw new PeerException("Shutdown");
}
futureStub = EndorserGrpc.newFutureStub(managedChannel);//这个为新加
return futureStub.processProposal(proposal);
}
public FabricProposalResponse.ProposalResponse sendProposal(FabricProposal.SignedProposal proposal) throws PeerException {
if (shutdown) {
throw new PeerException("Shutdown");
}
try {
blockingStub=EndorserGrpc.newBlockingStub(managedChannel);//这个为新加
return blockingStub.processProposal(proposal);
} catch (StatusRuntimeException e) {
logger.warn(String.format("RPC failed: %s", e.getStatus()));
throw new PeerException("Sending transaction to peer failed", e);
}
}
这个类上。
改动这个类并mvn package后,重新使用。
使用后发现hfclient长时间不用后,还是会抛出:
java.lang.IllegalArgumentException: delay: -846693464887 (expected: >= 0)
的异常,但已不影响正常使用了。现有代码是出这个异常会重新获取。有时也会报错,重试下也会成功。
用common-pool2线程池管理,idle超过一定时间的就移出,也就不会出问题了