运行期每隔几个小时不定时报错,但不影响运行,应如何排除?
问题描述
项目运行期每隔几个小时不定时报错,但不影响运行
报错信息如下:
2019-10-30 06:20:27.295 INFO 259227 --- [http-nio-9999-exec-3] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:422)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:683)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
报错频率如下:
2019-10-24 21:57:02.528
2019-10-25 19:32:24.896
2019-10-26 02:00:35.061
2019-10-26 20:07:44.157
2019-10-27 23:02:40.711
2019-10-28 02:04:25.915
2019-10-28 14:34:05.968
问题出现的环境背景及自己尝试过哪些方法
- 环境:SpringBoot 1.5.6、内嵌 Tomcat 8.5.16
- 尝试:添加
server.max-http-header-size=3145728
,结果无效 尝试:添加
logging.level.org.apache.coyote.http11=debug
,debug 信息如下:2019-11-06 19:54:52.752 DEBUG 731016 --- [http-nio-9999-exec-5] o.a.coyote.http11.Http11InputBuffer : Received[»h 2019-11-06 19:54:52.755 INFO 731016 --- [http-nio-9999-exec-5] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level. java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:422) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:683) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 2019-11-06 19:54:52.756 DEBUG 731016 --- [http-nio-9999-exec-5] o.apache.coyote.http11.Http11Processor : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@144b45bd:org.apache.tomcat.util.net.NioChannel@6e345528:java.nio.channels.SocketChannel[connected local=/xxx.xx.xxx.xxx:9999 remote=/xxx.xxx.xxx.xxx:51262]], Status in: [OPEN_READ], State out: [CLOSED]
相关代码
代码很简单,大概意思如下(从MQ获取消息后调用https请求):
public class Demo {
private ExecutorService executor = Executors.newCachedThreadPool();
private static final String URL = "https://www.testdemo.com/aaa/bbb/ccc";
// 从MQ中获取消息后调用该方法
public void dealMessage(JSONObject message) {
executor.execute(() -> doPostHttp(message));
}
// 执行请求
private void doPostHttp(JSONObject message) {
String result= HttpUtil.post(URL, message);
System.out.println(result);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Invalid character found in method name. HTTP method names must be tokens
发的请求里的 http method 有问题,最好把部分代码发出来看一下,正常的库发请求不可能把http方法发错
同样的问题困扰我很久,在思否提问时系统推荐了你的问题。
目前收集到的解决方案大概是这些:
1.修改
server.xml
中maxHttpHearderSize
参数。国内论坛大多提到这个解决方案,不排除有些程序的故障确实由这个配置引起,但经测试无效。2.据说是Tomcat个别版本的BUG。stackoverflow原帖地址这里提到tomcat8.5.32好像有这个问题。恰巧我出问题的SSM框架项目曾就部署在tomcat8.5.32,而我也确实看到有人反映通过更换tomcat版本解决了这个问题。但我将项目迁移到SpringBoot并使用内嵌tomcat部署时问题依然存在。
3.请求协议错误。HTTP请求和HTTPS请求搞混了。这是目前认为最有可能的原因,正在找办法验证。具体信息在上述stackoverflow帖子中也有提到。
另外可以尝试在springboot配置中加入
logging.level.org.springframework.web: trace
logging.level.org.apache: trace
进一步追踪问题。
目前还没能解决这个问题,如果哪位有想法欢迎交流。