wangduanduan / wangduanduan.github.io

Wubba Lubba dub-dub
https://wdd.js.org
27 stars 7 forks source link

Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING #184

Closed wangduanduan closed 5 years ago

wangduanduan commented 5 years ago

ajax获取某个资源,有时候浏览器报错,并且检查network面板的这天请求,发现里面没有响应体。

Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
wangduanduan commented 5 years ago

This is typically caused by a server not sending us the terminal 0-length chunk. We sit around waiting for more data with the request hung until the server closes the socket. At that point, we have no way to know whether we've received the entire file or not. This seems to be working as intended. The server needs to be fixed. When a server is done sending the final chunk of a file with chunked transfer-encoding, the server must send a final empty chunk. The server here appears not to be doing that, but just timing out the socket instead while the browser waits. There's no way for the browser to determine if it has the whole file or not if the server doesn't do this, so Chrome treats it as an error. The server needs to be fixed to send this final empty chunk. There's a software bug in there somewhere. https://bugs.chromium.org/p/chromium/issues/detail?id=461213

总结一下。这个不是chrome浏览器的问题,而是服务端没有发送大小为0的块作为主体结束的信号。

wangduanduan commented 5 years ago

分块编码允许服务把响应体分块发送给客户端,但是服务端必须发送一个大小为0的块作为结束标记,告诉浏览器,已经把响应体发送结束。否则浏览器就会在哪里傻傻的等着,直到报错。来自《http权威指南》

wechatimg31

wangduanduan commented 5 years ago

纸上得来终觉浅,绝知此事要抓包。通过wireshark抓包分析,可以看到有个End-of-chunk-coding,如果没有这个包,就说明是服务端问题。

jietu20190301-164542

wangduanduan commented 5 years ago

至于这个问题如何解决,我还不清楚。因为这个问题是偶现的,不太好搞。