-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Duplicated values in Sentry Baggage header cause eventual 431 "Request header fields too large" error on HTTP fetch #12350
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
Comments
@etnichols can you share more about the request? Can you verify that the request is indeed made as a |
Thanks for the reply @lforst!
Confirmed, here is an example snippet of our fetch code used: /* User Routes */
const fetchCurrentUser = (options) => fetch(`${BASE_URL}/api/user`, {
credentials: 'include',
cache: 'no-store',
})
.then((response) => (response.status === 401 ? (window.location.href = '/login') : response))
.then((response) => response.json()); I can provide a HAR file too if that would be helpful. |
.HAR file from our dev environment is here: app.tryinteract.dev-sentry-baggage-issue.har.zip |
I wonder if there is some other library involved that patches |
I also don't really see how this can happen with the code @etnichols shared without a third party interfering. @etnichols would you mind providing a minimal reproduction? Thanks. |
While creating the min repro (https://github.com/etnichols/sentry-baggage-min-repro) we found the root cause: re-using a const object for the fetch ❌ passes same object reference to every instantiation of fetchCurrentUser, which causes Sentry code to continually append
✅ spread operator creates a new object for each instantiation, no duplicated Baggage headers. const FETCH_OPTIONS = {
credentials: 'include',
method: 'GET',
};
const fetchCurrentUser = (options) =>
fetch(`/api/user`, { ...FETCH_OPTIONS }).then((response) => response.json()); While you could still consider adding de-dupe logic to the Header ctor code, this is 100% user error 🐒 apologies for the confusion. |
I honestly don't consider this a user error! We should make it harder to run into this probably by cloning the object or smth. |
Just chiming in to say that this has caused me quite the headache. const headers = {
Accept: "application/json",
Cookie: cookieString,
Origin: baseUrl,
};
const options = {
credentials: "include",
prefixUrl: process.env.VITE_API_SSR_HOST,
headers,
throwHttpErrors: false,
} as const;
const response = await ky("api/user", { ...options }); |
@4350pChris it's a nice coincidence that I am just now touching this part of the code base. I think I can get a fix in for this. |
A PR closing this issue has just been released 🚀This issue was referenced by PR #13907, which was included in the 8.35.0 release. |
@lforst I recently came across the same issue where duplicate strings are included in the Unfortunately, I don't have a repro example, and I'm unsure of what circumstances are necessary for the issue to occur. That said, and I apologize if this is naive on my part, but I don't understand the reasoning behind how the baggage header is derived and set. It would appear that the previous baggage header is merged in with the next baggage header. Again, let me know if I'm just missing something, but it would seem this is how the duplication is occurring. I'll add more details per my specific setup if I'm able to, but I'm working in a large, aged codebase which is making isolating the issue difficult. That said, I'm quite certain each new fetch request is initiated with a new |
The problem seems to still occur on the latest version for me as well. |
@jvnlwn @4350pChris could you both attempt to provide a small reproduction example that shows the behaviour you're seeing. I was actually quite confident my PR would fix this but I struggle to understand how it could still happen. Besides the above, do you use any other SDKs besides the JavaScript one? |
Closing due to lack of reproduction. Feel free to ping me here in case you find the time! |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
7.112.2
Framework Version
13.5.6
Link to Sentry event
n/a
SDK Setup
Steps to Reproduce
Expected Result
Non-duplicated Sentry
Baggage
header.Actual Result
App is experiencing the exact same issue as described in #11500. Each subsequent request made from our NextJS client includes a duplicated entry under the
Baggage
header. For example, we have an/account/settings
page that fires off 3 requests during load:request 1

request 2

request 3

this pattern continues until the one of the fetch calls recieves back a 431 "Request header fields too large" response, which usually results in app hanging until hard refresh.
Using
"@sentry/nextjs": "^7.112.2"
for our Next app.Taking a look at the logic that @lforst mentioned in #11500 (comment), I suspect this is a bug with the construction of the sentry baggage headers, specifically either here or here.
In both cases, doing a deduplication of existing key-value pairs might resolve the issue:
The text was updated successfully, but these errors were encountered: