Bug 215631

Summary: Webkit incorrectly reuses closed tcp connections: Failed to load resource: The network connection was lost.
Product: WebKit Reporter: kevmun
Component: WebCore JavaScriptAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Critical CC: ap, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari 13   
Hardware: Mac   
OS: macOS 10.15   

Description kevmun 2020-08-18 16:47:27 PDT
In our webapp using webkit, we see an issue with certain AJAX requests, "Failed to load resource: The network connection was lost."

We have observed that using Fetch (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) we hit a timing issue where the browser tries to reuse a connection that was recently closed. With optimal network conditions, it’s about a 2% chance of this occurring. With high latency packets, we can reproduce %15 of the time. 

Steps to repro:

Navigate at exactly 7 seconds (when our server terminates the connection, reproducing outside this environment will depend on the server timeouts).

We've observed our TCP connections to be in TIME_WAIT at the time of failure;

The docs here refer to webkit keeping connections open
https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/CommonPitfalls/CommonPitfalls.html
Comment 1 Radar WebKit Bug Importer 2020-08-19 00:50:06 PDT
<rdar://problem/67385261>
Comment 2 Alexey Proskuryakov 2020-08-19 15:30:11 PDT
> Navigate at exactly 7 seconds (when our server terminates the connection, reproducing outside this environment will depend on the server timeouts).

Can you share the server URL?
Comment 3 Alexey Proskuryakov 2020-08-31 13:36:47 PDT
As a workaround, can you use HTTP/2 instead instead of HTTP/1 or add `Keep-Alive: timeout=7` header?