1.起始:线上突然收到用户反馈,一个文件上传合并接口报错,其他文件无异常,该文件经多次重试仍无法成功
2.排查:查看前端nginx日志无异常,查看后台日志发现该用户使用该接口有报错情况
3.具体报错:
2022-09-07 09:18:32.644 INFO 10.5.164.168 30579---[http-nio-8080-exec-10] xxx.xxx.xxx.controller.OssController:426 - 分片上传 user: 15120048348 upload file: [三农报道]口感香甜.mp4 file size: 109014716 chunkSize: 52428800 identifier:379c826c537c2cc1cda2c14d738cf3cb
2022-09-07 09:21:59.651 INFO 10.5.164.168 30579---[http-nio-8080-exec-2] org.apache.coyote.http11.Http11Processor:175 - 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 request target [/aliyun/oss/merge?identifier=379c826c537c2cc1cda2c14d738cf3cb&fileName=[%E4%B8%AD%E5%9B%BD%E4%B8%89%E5%86%9C%E6%8A%A5%E9%81%93]%E9%A6%99%E6%B0%94%E6%B5%93%E9%83%81%E5%8F%A3%E6%84%9F%E9%A6%99%E7%94%9C.mp4&totalChunks=2]. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:491)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:260)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
4.问题分析:该问题由于fileName字段使用了不支持的字符[]导致,理论上还有其他不支持字符也会报错,猜测对该字段的值进行编码即可解决。
5.解决措施1:前端对fileName字段值使用 encodeURIComponent进行URL编码,经验证后端无影响,问题解决。
6.解决措施2:前端使用post方式传输参数,后端采用post方式requestBode接收参数,未验证,前后端一起改动比较麻烦,但理论可行。