Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃Ч Added graceful handling of aborted requests #1329

Merged
merged 2 commits into from
Jul 27, 2023

Conversation

ninadbstack
Copy link
Contributor

@ninadbstack ninadbstack commented Jul 27, 2023

What ?

  • Added graceful handling of aborted requests
  • Now we keep track of aborted requests and whenever we are going to make a session.send call we check if we have already received abortion event for same request id
  • If request was already aborted we dont print it out as Error: Protocol error (Fetch.fulfillRequest): Invalid InterceptionId.
  • We now print two new logs under debug mode, one for aborted request event and once when we ignore error above due to the same.

Why?

  • There are cases when a browser triggers a network request and cancels it before its resolved. It usually happens when a resource was originally required, but is now not required [ say you have an srcset with multiple entries and you change the width of the browser fast enough such that it starts loading one of the resources, but now it doesn't need it ]
  • In this case we would first receive Network.requestWillBeSent event, which we would eventually respond with Fetch.continueRequest or Fetch.fulfillRequest etc, but before we respond if the request gets cancelled [which invalidates Interception Id] we get above Protocol error.

Test:

  • This was hard to write test for as its hard to reproduce this race [ or browser cancelling a request ] to begin with
  • So we are using fetchWithTimeout helper so that we can mimic a cancellation from browser
  • In order to reproduce the race condition we specifically delay Fetch.continueRequest response by 1 sec so that request triggered by fetch is cancelled
  • Which is equivalent to calling a Fetch.* method with a request/interception Id of a request thats already cancelled

@ninadbstack ninadbstack requested a review from a team as a code owner July 27, 2023 04:34
@ninadbstack ninadbstack force-pushed the handle-aborted-requests-in-discovery branch 2 times, most recently from d16306d to 0b89f21 Compare July 27, 2023 07:44
@ninadbstack ninadbstack force-pushed the handle-aborted-requests-in-discovery branch from 0b89f21 to 59c3324 Compare July 27, 2023 07:52
Co-authored-by: Samarjeet <samarsault@gmail.com>
Copy link
Contributor

@itsjwala itsjwala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, nice!

@ninadbstack ninadbstack merged commit c09c8d4 into master Jul 27, 2023
34 checks passed
@ninadbstack ninadbstack deleted the handle-aborted-requests-in-discovery branch July 27, 2023 10:47
@ninadbstack ninadbstack added the 馃Ч maintenance General maintenance label Jul 27, 2023
@ninadbstack ninadbstack changed the title Added graceful handling of aborted requests 馃Ч Added graceful handling of aborted requests Jul 27, 2023
rishigupta1599 pushed a commit that referenced this pull request Aug 7, 2023
* Added graceful handling of aborted requests

* Update packages/core/src/network.js

Co-authored-by: Samarjeet <samarsault@gmail.com>

---------

Co-authored-by: Samarjeet <samarsault@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃Ч maintenance General maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants