elasticsearch java.io.IOException: 遠端主機強迫關閉了一個現有的連線。
阿新 • • 發佈:2019-02-20
今天在自定義分詞的時候用http方法呼叫了一下線上ik分詞,結果就出現了
[2018-10-24T22:56:03,542][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [BGZTprP] caught exception while handling client http traffic, closing connection [id: 0xe4dfb70d, L:/127.0.0.1:9200 - R:/127.0.0.1:49530] 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:197) ~[?:?] at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) ~[?:?] at io.netty.buffer.PooledHeapByteBuf.setBytes(PooledHeapByteBuf.java:261) ~[netty-buffer-4.1.16.Final.jar:4.1.16.Final] at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1106) ~[netty-buffer-4.1.16.Final.jar:4.1.16.Final] at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:343) ~[netty-transport-4.1.16.Final.jar:4.1.16.Final] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:123) [netty-transport-4.1.16.Final.jar:4.1.16.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) [netty-transport-4.1.16.Final.jar:4.1.16.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:545) [netty-transport-4.1.16.Final.jar:4.1.16.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499) [netty-transport-4.1.16.Final.jar:4.1.16.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) [netty-transport-4.1.16.Final.jar:4.1.16.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [netty-common-4.1.16.Final.jar:4.1.16.Final] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]
經過分析是自己寫的HttpUtil的問題。
原因分析
HttpUtil在單元測試的時候jvm執行結束,而HttpUtil裡面有一個CloseableHttpClient,jvm結束的時候CloseableHttpClient沒有正常關閉導致的,優化了一下程式碼,在使用完釋放掉CloseableHttpClient,也就是呼叫一下close()方法。