简体   繁体   中英

IOUtils.toString() exception java.net.SocketTimeoutException: null

On a web application, i use async servlet.

When i use IOUtils.toString() method, convert http inputstream to String.

But get java.net.SocketTimeoutException: null on production server ,

and unable to reproduce on my local machine.

Below is the stack trace:

java.net.SocketTimeoutException: null
    at org.apache.tomcat.util.net.NioBlockingSelector.read(NioBlockingSelector.java:202) ~[tomcat-coyote.jar:8.0.42]
    at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:250) ~[tomcat-coyote.jar:8.0.42]
    at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:231) ~[tomcat-coyote.jar:8.0.42]
    at org.apache.coyote.http11.InternalNioInputBuffer.fill(InternalNioInputBuffer.java:133) ~[tomcat-coyote.jar:8.0.42]
    at org.apache.coyote.http11.InternalNioInputBuffer$SocketInputBuffer.doRead(InternalNioInputBuffer.java:177) ~[tomcat-coyote.jar:8.0.42]
    at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:110) ~[tomcat-coyote.jar:8.0.42]
    at org.apache.coyote.http11.AbstractInputBuffer.doRead(AbstractInputBuffer.java:362) ~[tomcat-coyote.jar:8.0.42]
    at org.apache.coyote.Request.doRead(Request.java:476) ~[tomcat-coyote.jar:8.0.42]
    at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:350) ~[catalina.jar:8.0.42]
    at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:395) ~[tomcat-util.jar:8.0.42]
    at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:375) ~[catalina.jar:8.0.42]
    at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:190) ~[catalina.jar:8.0.42]
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) ~[na:1.8.0_65]
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) ~[na:1.8.0_65]
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) ~[na:1.8.0_65]
    at java.io.InputStreamReader.read(InputStreamReader.java:184) ~[na:1.8.0_65]
    at java.io.Reader.read(Reader.java:140) ~[na:1.8.0_65]
    at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2001) ~[commons-io-2.4.jar:2.4]
    at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1980) ~[commons-io-2.4.jar:2.4]
    at org.apache.commons.io.IOUtils.copy(IOUtils.java:1957) ~[commons-io-2.4.jar:2.4]
    at org.apache.commons.io.IOUtils.copy(IOUtils.java:1907) ~[commons-io-2.4.jar:2.4]
    at org.apache.commons.io.IOUtils.toString(IOUtils.java:778) ~[commons-io-2.4.jar:2.4]
    at org.apache.commons.io.IOUtils.toString(IOUtils.java:803) ~[commons-io-2.4.jar:2.4]

Socket timeout implies either the connect timeout or the read timeout has been reached. This error is not caused by IOUtils.toString().

The connect timeout will be thrown immediately when trying to connect to a remote endpoint. if the socket is open at the remote end but no data is returned when trying to read data from the socket you will receive a read timeout.

Both the read and connect timeouts can be set although I suggest using telnet to validate the port is open at the remote end first outside of your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM