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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browser): Ensure keepalive flag is correctly set for parallel requests #7553

Merged
merged 3 commits into from Mar 21, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Mar 21, 2023

We noticed that sometimes request would remain in a seemingly pending state.
After some investigation, we found out that the limit of 64kb for keepalive-enabled fetch requests is not per request but for all parallel requests running at the same time.

This PR fixes this by keeping track of how large the pending body sizes are, and setting keepalive accordingly.

I tried this in my local reproduction app, where it now worked as expected!

When do we use keepalive now

We use keepalive if:

  • total currently pending body size < 60k
  • total # of pending requests < 15

This should defensively work for relevant cases.

Why do we want to have keepalive, when possible?

Especially for replays and transactions, having keepalive enabled means we can capture more data when a user leaves the page, which would otherwise be lost. This lead to problems with Next.js transaction collection, for example. In Replay, we want to be able to make sure to do a final flush before the user leaves the page.

Spec reference

Fixes #7546
Fixes #6049

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Should we also update the doc string?

The spec says:

If the sum of contentLength and inflightKeepaliveBytes is greater than 64 kibibytes, then return a network error.

@AbhiPrasad AbhiPrasad changed the title fix: Ensure keepalive flag is correctly set for parallel requests fix(browser): Ensure keepalive flag is correctly set for parallel requests Mar 21, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 21, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 20.44 KB (+0.12% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 63.55 KB (+0.08% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.13 KB (+0.14% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 56.59 KB (+0.1% 🔺)
@sentry/browser - Webpack (gzipped + minified) 21.6 KB (+0.12% 🔺)
@sentry/browser - Webpack (minified) 71.67 KB (+0.08% 🔺)
@sentry/react - Webpack (gzipped + minified) 21.63 KB (+0.12% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 51.96 KB (+0.05% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 27.77 KB (+0.09% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.08 KB (+0.11% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 44.22 KB (+0.01% 🔺)
@sentry/replay - Webpack (gzipped + minified) 38.28 KB (0%)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 62.4 KB (+0.04% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 55.95 KB (+0.07% 🔺)

@mydea
Copy link
Member Author

mydea commented Mar 21, 2023

Updated the doc accordingly!

@HazAT
Copy link
Member

HazAT commented Mar 21, 2023

ref: #1496

@mydea mydea merged commit 7b9198f into develop Mar 21, 2023
48 checks passed
@mydea mydea deleted the fn/fix-keepalive branch March 21, 2023 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable keepalive for error fetch requests Sentry requests are pending indefinitely
4 participants