如何解决“在HTTP协议中找到无效字符 [HTTP/1.10x0aHost:]”?

huangapple go评论148阅读模式
英文:

How to solve "Invalid character found in the HTTP protocol [HTTP/1.10x0aHost:]"?

问题

在将我的SpringBoot项目部署到AWS EC2实例后,经常出现异常:

2020-07-31 01:56:21.487 DEBUG 7340 --- [nio-8080-exec-1] org.apache.tomcat.util.net.NioEndpoint   : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@3d89313d:org.apache.tomcat.util.net.NioChannel@11d95ea0:java.nio.channels.SocketChannel[connected local=/172.31.38.151:8080 remote=/198.98.61.139:33842]], Read direct from socket: [175]

2020-07-31 01:56:21.487  INFO 28770 --- [nio-8080-exec-4] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the HTTP protocol [HTTP/1.10x0aHost:]
        at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:560) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:260) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

它没有破坏项目,所有功能都正常运行。
但我不知道它是否会在将来引起问题,所以我想现在解决它。

请问有人能给我一些关于这个异常的原因的提示吗?

英文:

After I deployed my SpringBoot project to an AWS EC2 instance, an exception shows up frequently:

2020-07-31 01:56:21.487 DEBUG 7340 --- [nio-8080-exec-1] o.a.tomcat.util.net.SocketWrapperBase    : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@3d89313d:org.apache.tomcat.util.net.NioChannel@11d95ea0:java.nio.channels.SocketChannel[connected local=/172.31.38.151:8080 remote=/198.98.61.139:33842]], Read from buffer: [0]
2020-07-31 01:56:21.487 DEBUG 7340 --- [nio-8080-exec-1] org.apache.tomcat.util.net.NioEndpoint   : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@3d89313d:org.apache.tomcat.util.net.NioChannel@11d95ea0:java.nio.channels.SocketChannel[connected local=/172.31.38.151:8080 remote=/198.98.61.139:33842]], Read direct from socket: [175]

2020-07-31 01:56:21.487  INFO 28770 --- [nio-8080-exec-4] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the HTTP protocol [HTTP/1.10x0aHost:]
        at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:560) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:260) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

It doesn't break the project, and every functionality is running fine.
But I don't know if it will cause some problems in the future, so I would like to solve it now.

Could anyone give me some hints about what causes this exception please?

答案1

得分: 1

我遇到了相同的问题,并发现与Tomcat 8.5版本8.5.44引入的更改有关。描述如下:修复:63578:改进对无效请求的处理,以便将400响应返回给客户端,而不是500响应。(markt)(http://tomcat.apache.org/tomcat-8.5-doc/changelog.html#Tomcat_8.5.44_(markt))

在这种情况下,一些旧代码对HTTP GET端点进行手动请求,发送的内容类似于:

"GET " + path + " HTTP/1.1\n"

需要更改为:

"GET " + path + " HTTP/1.1\r\n"以解决问题。

将详细信息放在这里,供将来遇到相同问题的其他人参考。Tomcat可能已经修复了这个问题,以使其更加兼容,这可能会破坏未能正确处理的旧代码。

英文:

I had the same problem and found it related to a change to Tomcat 8.5 introduced in version 8.5.44. The description on this is Fix: 63578: Improve handling of invalid requests so that 400 responses are returned to the client rather than 500 responses. (markt) (http://tomcat.apache.org/tomcat-8.5-doc/changelog.html#Tomcat_8.5.44_(markt))

In that situation some legacy code making a manual request being made to an HTTP GET endpoint was sending something like:

"GET " + path + " HTTP/1.1\n"

This needed to be changed to:

"GET " + path + " HTTP/1.1\r\n" to fix the problem.

Putting details here for future reference to others with the same issue. Tomcat would have fixed this to be more compliant, that might break legacy code that was not doing the right thing.

huangapple
  • 本文由 发表于 2020年7月31日 09:15:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63184425.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定