gpt4 book ai didi

java.net.SocketTimeoutException : null

转载 作者:行者123 更新时间:2023-12-01 17:42:45 45 4
gpt4 key购买 nike

我正在开发一个 Web 应用程序,它接受来自第三方的 json 数据,处理该数据并使用处理后的 json 数据响应它们。

我在生产服务器上收到 java.net.SocketTimeoutException: null ,但无法在本地计算机上重现。下面是堆栈跟踪:

java.net.SocketTimeoutException: null
at org.apache.tomcat.util.net.NioBlockingSelector.read(NioBlockingSelector.java:191)
at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:246)
at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:227)
at org.apache.coyote.http11.InternalNioInputBuffer.readSocket(InternalNioInputBuffer.java:422)
at org.apache.coyote.http11.InternalNioInputBuffer.fill(InternalNioInputBuffer.java:794)
at org.apache.coyote.http11.InternalNioInputBuffer$SocketInputBuffer.doRead(InternalNioInputBuffer.java:819)
at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:124)
at org.apache.coyote.http11.AbstractInputBuffer.doRead(AbstractInputBuffer.java:346)
at org.apache.coyote.Request.doRead(Request.java:422)
at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:290)
at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:449)
at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:315)
at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.read1(BufferedReader.java:205)
at java.io.BufferedReader.read(BufferedReader.java:279)
at java.io.Reader.read(Reader.java:140)

引发此异常的代码段(特别是“while”条件):

public static String getPostData(HttpServletRequest request) throws 
IOException {
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = null;
try {
InputStream inputStream = request.getInputStream();
if (inputStream != null) {
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
char[] charBuffer = new char[128];
int bytesRead = -1;
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
stringBuilder.append(charBuffer, 0, bytesRead);
}
} else {
stringBuilder.append("");
}
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
}
return stringBuilder.toString();
}

此应用程序部署在具有相同服务器配置的 3 个不同的 AWS 区域中,令人惊讶的是只有其中一个区域抛出此异常,而且也仅针对极少数随机请求。

感谢任何帮助。提前致谢!

最佳答案

为了重现套接字超时异常,您必须让客户端开始下载,然后暂停下载一段时间。您可以通过以下方式实现此目的

关于java.net.SocketTimeoutException : null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43529130/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com