响应正文坏块头-GET请求上的I / O错误

时间:2018-10-03 01:04:47

标签: spring-boot embedded-tomcat-8

设置-2个Rest服务,spring-boot 2.x,嵌入式tomcat 8.x

服务A使用restTemplate调用服务B,该循环在运行300次的测试循环中,在循环中的第100个间隔中,都会引发异常“坏块头异常”。

启用调试(app.herokuapps.com/app1 ---> www.app1.com app.herokuapps.com/app2 ---> www.app2.com app.herokuapps.com/app3 ---> www.app3.com ),以下是分析:

前99次迭代-请求/响应标头具有Connection:保持活动状态,并且主体/流以回车\ r \ n结束

请求标头

<logger name="org.apache.http" level="DEBUG"/>

响应标题

"GET /rest/customers/1000000030 HTTP/1.1[\r][\n]"
"Accept-Language: en-us[\r][\n]"
"Accept: application/json[\r][\n]"
"Content-Type: application/json[\r][\n]"
"Host: localhost:9192[\r][\n]"
"Connection: Keep-Alive[\r][\n]"
"User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_25)[\r][\n]"
"Accept-Encoding: gzip,deflate[\r][\n]"
"[\r][\n]"

第100次通话-请求标头具有Connection:保持活动状态,但响应消息处理程序具有 Connection:close和body / stream而无回车符\ r \ n
http-outgoing-0 <<“流结束”
GET请求“ http://localhost:9192/rest/customers/1000000030”的I / O错误:错误的块头

请求标头

"HTTP/1.1 200 [\r][\n]"
"X-Content-Type-Options: nosniff[\r][\n]"
"X-XSS-Protection: 1; mode=block[\r][\n]"
"Cache-Control: no-cache, no-store, max-age=0, must-revalidate[\r][\n]"
"Pragma: no-cache[\r][\n]"
"Expires: 0[\r][\n]"
"X-Frame-Options: DENY[\r][\n]"
"X-Content-Type-Options: nosniff[\r][\n]"
"X-Content-Type-Options: nosniff[\r][\n]"
"X-Content-Type-Options: nosniff[\r][\n]"
"Cache-Control: no-cache, no-store, max-age=0, must-revalidate[\r][\n]"
"Pragma: no-cache[\r][\n]"
"Expires: 0[\r][\n]"
"Connection: close[\r][\n]"
"Transfer-Encoding: chunked[\r][\n]"
"Date: Wed, 03 Oct 2018 00:31:53 GMT[\r][\n]"
"Content-Type: application/json;charset=UTF-8[\r][\n]"
"[\r][\n]"
"{"customerNumber":"1000000030"}[\r][\n]"

响应标题

"GET /rest/customers/1000000030 HTTP/1.1[\r][\n]"
"Accept-Language: en-us[\r][\n]"
"Accept: application/json[\r][\n]"
"Content-Type: application/json[\r][\n]"
"Host: localhost:9192[\r][\n]"
"Connection: Keep-Alive[\r][\n]"
"User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_25)[\r][\n]"
"Accept-Encoding: gzip,deflate[\r][\n]"
"[\r][\n]"

a。为什么服务器在通话100次后关闭连接?

似乎是这样的原因-带有NIO连接器默认设置的Tomcat 8:

  • 每个服务器可以处理的最大连接数是 maxConnections = 10000
  • 每个连接超时connectionTimeout = 60秒
  • 最大线程数定义每个连接中可以处理多少个同时请求maxThreads = 200
  • 最少可用的备用线程(非连接) = minSpareThreads = 10
  • 一个连接中的最大保持活动请求数量 maxKeepAliveRequests = 100(这似乎正在关闭 连接,并且不发送回车作为响应的一部分 主体生成缓冲区读取I / O异常)

b。关闭连接时,服务器为什么不发送终止或回车?这是春天还是未来问题?

c。如何或需要更改设置以避免这种情况? maxKeepAliveRequests没有在Spring应用程序属性中公开,唯一的替代方法是实现一个实现WebServerFactoryCustomizer的客户容器,然后手动进行替代。

请告知这是否是服务器上关闭连接事件的错误?

1 个答案:

答案 0 :(得分:1)

使用RestTemplate交换功能时遇到了这个问题,我只是过滤了Connection标头,然后错误消失了。

相关问题