Chrome 刚好 3 秒后取消 URL_REQUEST

Chrome cancels URL_REQUEST after exactly 3 seconds

好吧,这很奇怪。

我正在开发一个 php 脚本,该脚本会在请求时执行大量工作(图像处理)。所以这并不罕见,它会在 10 秒内发出响应,有时会长达 30 秒:这是一个很长的脚本,这对下一部分很重要。

在记录图像处理代码时,我注意到应该只调用一次的进程被调用了两次。

原因:Chrome 3 秒后取消第一个请求,然后再次请求相同的 URL。

顺序总是一样的。

  1. URL 请求
  2. 3 秒后取消
  3. 使用 http 方案自动重新加载
  4. 307 由于我们服务器上的 HSTS
  5. URL 再次请求 https
  6. 这个加载正确

已取消的请求在“计时”选项卡中显示为已停止。

这只发生在 Chrome(对我来说是 92.0.4515.107)。我在 Firefox 中没有看到这种行为。

现在如何重现这一巫术?很简单,我可以在 2 个不同的提供商(GCE 和 OVH)上的 2 个不同的服务器上进行复制,并且它有一个奇怪的 link 初始请求的持续时间 URL.

  1. 在您的网络服务器上创建一个新的 php 脚本,只包含

    <?php sleep(10); echo 'Done'; ?>

  2. 在 Chrome

    中调用您的脚本 URL
  3. 第一次调用会成功

  4. 但接下来的所有调用肯定会触发“序列”

通过查看 Chrome 日志,我开始认为这有一个 link 和 HTTP2_SESSION

t=235805 [st=   5]     +HTTP_TRANSACTION_SEND_REQUEST  [dt=1]
t=235806 [st=   6]        HTTP_TRANSACTION_HTTP2_SEND_REQUEST_HEADERS
                          --> :method: GET
                              :authority: my.server.com
                              :scheme: https
                              :path: /admin/ot/test1.php
                              pragma: no-cache
                              cache-control: no-cache
                              authorization: [38 bytes were stripped]
                              sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
                              sec-ch-ua-mobile: ?0
                              upgrade-insecure-requests: 1
                              user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
                              accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
                              sec-fetch-site: none
                              sec-fetch-mode: navigate
                              sec-fetch-user: ?1
                              sec-fetch-dest: document
                              accept-encoding: gzip, deflate, br
                              accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
                              cookie: [409 bytes were stripped]
t=235806 [st=   6]     -HTTP_TRANSACTION_SEND_REQUEST
t=235806 [st=   6]     +HTTP_TRANSACTION_READ_HEADERS  [dt=3012]
t=238818 [st=3018]        CANCELLED
t=238818 [st=3018] -REQUEST_ALIVE

上面的URL_REQUEST,我们学的不多。我们只在 3 秒后看到“CANCELLED”。

但是 HTTP2_SESSION 显示了一个奇怪的错误:

27185: HTTP2_SESSION
my.server.com:443 (DIRECT)
Start Time: 2021-07-22 17:13:09.460

t=222444 [st=    0] +HTTP2_SESSION  [dt=28616+]
                     --> host = "my.server.com:443"
                     --> proxy = "DIRECT"
t=222444 [st=    0]    HTTP2_SESSION_INITIALIZED
                       --> protocol = "h2"
                       --> source_dependency = 27181 (SOCKET)
t=222445 [st=    1]    HTTP2_SESSION_SEND_SETTINGS
                       --> settings = ["[id:1 (SETTINGS_HEADER_TABLE_SIZE) value:65536]","[id:3 (SETTINGS_MAX_CONCURRENT_STREAMS) value:1000]","[id:4 (SETTINGS_INITIAL_WINDOW_SIZE) value:6291456]","[id:6 (SETTINGS_MAX_HEADER_LIST_SIZE) value:262144]"]
t=222445 [st=    1]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 15663105
                       --> window_size = 15728640
t=222445 [st=    1]    HTTP2_SESSION_SEND_WINDOW_UPDATE
                       --> delta = 15663105
                       --> stream_id = 0
t=222446 [st=    2]    HTTP2_SESSION_SEND_HEADERS
                       --> exclusive = true
                       --> fin = true
                       --> has_priority = true
                       --> :method: GET
                           :authority: my.server.com
                           :scheme: https
                           :path: /admin/ot/test1.php
                           pragma: no-cache
                           cache-control: no-cache
                           authorization: [38 bytes were stripped]
                           sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
                           sec-ch-ua-mobile: ?0
                           upgrade-insecure-requests: 1
                           user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
                           accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
                           sec-fetch-site: none
                           sec-fetch-mode: navigate
                           sec-fetch-user: ?1
                           sec-fetch-dest: document
                           accept-encoding: gzip, deflate, br
                           accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
                           cookie: [409 bytes were stripped]
                       --> parent_stream_id = 0
                       --> source_dependency = 27179 (HTTP_STREAM_JOB)
                       --> stream_id = 1
                       --> weight = 256
t=222471 [st=   27]    HTTP2_SESSION_RECV_SETTINGS
t=222471 [st=   27]    HTTP2_SESSION_SEND_SETTINGS_ACK
t=222471 [st=   27]    HTTP2_SESSION_RECV_SETTING
                       --> id = "3 (SETTINGS_MAX_CONCURRENT_STREAMS)"
                       --> value = 100
t=222471 [st=   27]    HTTP2_SESSION_UPDATE_STREAMS_SEND_WINDOW_SIZE
                       --> delta_window_size = 983041
t=222471 [st=   27]    HTTP2_SESSION_RECV_SETTING
                       --> id = "4 (SETTINGS_INITIAL_WINDOW_SIZE)"
                       --> value = 1048576
t=222471 [st=   27]    HTTP2_SESSION_RECV_SETTING
                       --> id = "6 (SETTINGS_MAX_HEADER_LIST_SIZE)"
                       --> value = 65536
t=222471 [st=   27]    HTTP2_SESSION_RECV_WINDOW_UPDATE
                       --> delta = 983041
                       --> stream_id = 0
t=222471 [st=   27]    HTTP2_SESSION_UPDATE_SEND_WINDOW
                       --> delta = 983041
                       --> window_size = 1048576
t=222471 [st=   27]    HTTP2_SESSION_RECV_SETTINGS_ACK
t=232550 [st=10106]    HTTP2_SESSION_RECV_HEADERS
                       --> fin = false
                       --> :status: 200
                           date: Thu, 22 Jul 2021 15:13:09 GMT
                           vary: Accept-Encoding
                           content-encoding: gzip
                           strict-transport-security: max-age=63072000; includeSubDomains; preload
                           x-ua-compatible: IE=Edge
                           x-frame-options: sameorigin
                           x-content-type-options: nosniff
                           x-xss-protection: 1; mode=block
                           content-length: 24
                           content-type: text/html; charset=CP1252
                           cache-control: 
                           age: 0
                           x-cache: NOT CACHABLE
                           accept-ranges: bytes
                           via: 1.1 google
                           alt-svc: clear
                       --> stream_id = 1
t=232550 [st=10106]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -1
                       --> window_size = 15728639
t=232550 [st=10106]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 1
                       --> window_size = 15728640
t=232550 [st=10106]    HTTP2_SESSION_RECV_DATA
                       --> fin = false
                       --> size = 24
                       --> stream_id = 1
t=232550 [st=10106]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -24
                       --> window_size = 15728616
t=232550 [st=10106]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -110
                       --> window_size = 15728506
t=232550 [st=10106]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 110
                       --> window_size = 15728616
t=232550 [st=10106]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -1
                       --> window_size = 15728615
t=232550 [st=10106]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 1
                       --> window_size = 15728616
t=232550 [st=10106]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -71
                       --> window_size = 15728545
t=232551 [st=10107]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 71
                       --> window_size = 15728616
t=232551 [st=10107]    HTTP2_SESSION_RECV_DATA
                       --> fin = true
                       --> size = 0
                       --> stream_id = 1
t=232551 [st=10107]    HTTP2_SESSION_PING
                       --> is_ack = false
                       --> type = "received"
                       --> unique_id = 0
t=232551 [st=10107]    HTTP2_SESSION_PING
                       --> is_ack = true
                       --> type = "sent"
                       --> unique_id = 0
t=232552 [st=10108]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 24
                       --> window_size = 15728640
t=235806 [st=13362]    HTTP2_SESSION_SEND_HEADERS
                       --> exclusive = true
                       --> fin = true
                       --> has_priority = true
                       --> :method: GET
                           :authority: my.server.com
                           :scheme: https
                           :path: /admin/ot/test1.php
                           pragma: no-cache
                           cache-control: no-cache
                           authorization: [38 bytes were stripped]
                           sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
                           sec-ch-ua-mobile: ?0
                           upgrade-insecure-requests: 1
                           user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
                           accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
                           sec-fetch-site: none
                           sec-fetch-mode: navigate
                           sec-fetch-user: ?1
                           sec-fetch-dest: document
                           accept-encoding: gzip, deflate, br
                           accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
                           cookie: [409 bytes were stripped]
                       --> parent_stream_id = 0
                       --> source_dependency = 27212 (HTTP_STREAM_JOB)
                       --> stream_id = 3
                       --> weight = 256
t=238818 [st=16374]    HTTP2_SESSION_SEND_RST_STREAM
                       --> description = ""
                       --> error_code = "8 (CANCEL)"
                       --> stream_id = 3
t=238846 [st=16402]    HTTP2_SESSION_SEND_HEADERS
                       --> exclusive = true
                       --> fin = true
                       --> has_priority = true
                       --> :method: GET
                           :authority: my.server.com
                           :scheme: https
                           :path: /admin/ot/test1.php
                           pragma: no-cache
                           cache-control: no-cache
                           authorization: [38 bytes were stripped]
                           upgrade-insecure-requests: 1
                           user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
                           accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
                           sec-fetch-site: none
                           sec-fetch-mode: navigate
                           sec-fetch-user: ?1
                           sec-fetch-dest: document
                           sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
                           sec-ch-ua-mobile: ?0
                           accept-encoding: gzip, deflate, br
                           accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
                           cookie: [409 bytes were stripped]
                       --> parent_stream_id = 0
                       --> source_dependency = 27225 (HTTP_STREAM_JOB)
                       --> stream_id = 5
                       --> weight = 256
t=249924 [st=27480]    HTTP2_SESSION_RECV_HEADERS
                       --> fin = false
                       --> :status: 200
                           date: Thu, 22 Jul 2021 15:13:25 GMT
                           vary: Accept-Encoding
                           content-encoding: gzip
                           strict-transport-security: max-age=63072000; includeSubDomains; preload
                           x-ua-compatible: IE=Edge
                           x-frame-options: sameorigin
                           x-content-type-options: nosniff
                           x-xss-protection: 1; mode=block
                           content-length: 24
                           content-type: text/html; charset=CP1252
                           cache-control: 
                           age: 0
                           x-cache: NOT CACHABLE
                           accept-ranges: bytes
                           via: 1.1 google
                           alt-svc: clear
                       --> stream_id = 5
t=249924 [st=27480]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -1
                       --> window_size = 15728639
t=249924 [st=27480]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 1
                       --> window_size = 15728640
t=249924 [st=27480]    HTTP2_SESSION_RECV_DATA
                       --> fin = false
                       --> size = 24
                       --> stream_id = 5
t=249924 [st=27480]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -24
                       --> window_size = 15728616
t=249925 [st=27481]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -94
                       --> window_size = 15728522
t=249925 [st=27481]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 94
                       --> window_size = 15728616
t=249925 [st=27481]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -1
                       --> window_size = 15728615
t=249925 [st=27481]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 1
                       --> window_size = 15728616
t=249925 [st=27481]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = -104
                       --> window_size = 15728512
t=249925 [st=27481]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 104
                       --> window_size = 15728616
t=249925 [st=27481]    HTTP2_SESSION_RECV_DATA
                       --> fin = true
                       --> size = 0
                       --> stream_id = 5
t=249925 [st=27481]    HTTP2_SESSION_PING
                       --> is_ack = false
                       --> type = "received"
                       --> unique_id = 2
t=249925 [st=27481]    HTTP2_SESSION_PING
                       --> is_ack = true
                       --> type = "sent"
                       --> unique_id = 2
t=249927 [st=27483]    HTTP2_SESSION_UPDATE_RECV_WINDOW
                       --> delta = 24
                       --> window_size = 15728640 

演练:

t=238818 [st=16374]    HTTP2_SESSION_SEND_RST_STREAM
                       --> description = ""
                       --> error_code = "8 (CANCEL)"
                       --> stream_id = 3

老实说,我不知道该怎么办。这可以很容易地重现,但我不明白为什么会这样。

Chrome 在我的公司主要用于我们的内部工具,所以我发现它由于神秘原因连续 2 次重新加载繁重的处理 URL。

如有任何帮助,我们将不胜感激。

哦,我确实禁用了所有扩展程序。它没有帮助。无论如何,我在 Chrome 日志中没有看到任何关于任何扩展干预的提及。

同样的问题,我用Firefox的时候没有发现这样的问题。一开始怀疑是服务端配置问题。后来发现换了环境问题依旧。最后定位到浏览器端,不知道具体是什么原因

我认为这个问题可以在响应延迟超过 3 秒的任何域和服务器端的任何技术上重现。我想这是一个 chrome 问题。我用 ASP.net MVC 和 AWS Beanstalk 托管复制了它。当您限制连接以获得更慢的响应时间时,我还在 https://example.com/ 上以不同的方式复制了它。

要复制它(在 Chrome 版本 92.0.4515.159(官方构建)(64 位)上):

  1. 打开 Dev Tools 并添加 Very Slow Network Throttling Profile 如下
  2. 通过粘贴转到 url:https://example.com/ -> 这应该有效
  3. 按 F5 刷新页面 -> 这应该也有效
  4. 现在,非常重要,只需单击地址栏两次即可看到: 然后按回车键。现在 chrome 的行为有所不同,首先它会尝试 https url,如果 3 秒内没有响应,它会重定向到 http。取消的请求是我正在谈论的那个。

也许这会帮助某人解决问题。

如果您的服务器不支持https,请尝试输入'http://'为每个请求指定协议。否则 Chrome 会自动尝试 https。需要3秒,然后去http.