环境 jectd 版本 0.5
etcd 版本 3.4
本人泥腿子 java 对于使用第三方包,假如是第三方包抛出异常,是不是没办法捕获解决。
如果我手动关闭 etcd 服务端,就会这样,这个异常是 jetcd 包里抛出的
00:22:31.569 [grpc-default-executor-1] INFO com.example.demo.EtcdClient - Watching for key=a
00:22:31.577 [grpc-default-executor-1] INFO com.example.demo.EtcdClient - type=PUT, key=a, value=24444
00:22:58.621 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] INBOUND DATA: streamId=3 padding=0 endStream=false length=52 bytes=000000002f0a1a08b298eaf1948386fccd0110cdd2918bd2b881cf8e01181120035a11120f0a01611010181120022a0433333333
00:22:58.622 [grpc-default-executor-1] INFO com.example.demo.EtcdClient - Watching for key=a
00:22:58.622 [grpc-default-executor-1] INFO com.example.demo.EtcdClient - type=PUT, key=a, value=3333
00:23:23.851 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] INBOUND GO_AWAY: lastStreamId=2147483647 errorCode=0 length=0 bytes=
00:23:23.856 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] INBOUND PING: ack=false bytes=73747577769755401
00:23:23.856 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] OUTBOUND PING: ack=true bytes=73747577769755401
00:23:23.857 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x138691d4, L:/127.0.0.1:58759 - R:/127.0.0.1:2379] OUTBOUND GO_AWAY: lastStreamId=0 errorCode=2 length=24 bytes=436f6e6e656374696f6e2072657365742062792070656572
00:23:23.861 [grpc-nio-worker-ELG-1-2] DEBUG io.netty.handler.codec.http2.Http2ConnectionHandler - [id: 0x138691d4, L:/127.0.0.1:58759 ! R:/127.0.0.1:2379] Sending GOAWAY failed: lastStreamId '0', errorCode '2', debugData 'Connection reset by peer'. Forcing shutdown of the connection.
java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.writev0(Native Method)
at sun.nio.ch.SocketDispatcher.writev(SocketDispatcher.java:51)
at sun.nio.ch.IOUtil.write(IOUtil.java:148)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:504)
at io.netty.channel.socket.nio.NioSocketChannel.doWrite(NioSocketChannel.java:423)
然后我重启 etcd 服务端,继续 put key 还是能继续 watch 到的:
00:23:50.692 [grpc-nio-worker-ELG-1-3] DEBUG io.grpc.netty.NettyClientHandler - [id: 0x56feb4a4, L:/127.0.0.1:58801 - R:/127.0.0.1:2379] INBOUND DATA: streamId=3 padding=0 endStream=false length=71 bytes=00000000420a1a08b298eaf1948386fccd0110cdd2918bd2b881cf8e01181320045a11120f0a01611010181220032a04333333335a11120f0a01611010181320...
00:23:50.692 [grpc-default-executor-2] INFO com.example.demo.EtcdClient - Watching for key=a
00:23:50.693 [grpc-default-executor-2] INFO com.example.demo.EtcdClient - type=PUT, key=a, value=3333
00:23:50.693 [grpc-default-executor-2] INFO com.example.demo.EtcdClient - type=PUT, key=a, value=4444
假如我在线上要用这个 java 的 etcd 客户端,我肯定起个线程来 watch,但是问题来了,假如 etcd 挂了 抛出了这个异常 然后这个异常导致线程退出,我难道还要线程退出的时候重新开始 watch 吗,这样感觉就麻烦了。话说面对这样的情况 该如何优雅的解决,诚心请教各位大佬了
1
0576coder OP 有人解答一下吗- -
|
2
brucewuio 2020-07-20 17:09:10 +08:00
写个 while 循环不就好了,循环内 catch
|
4
nidalee 2021-01-17 00:19:51 +08:00
LZ 最后怎么处理这个?我单起一个线程起监听,发现一段时间后,监听就无征兆的掉了,跟你说的问题有点类似
|