The document exceeds maximum allowed BSON object size after serialization

On our Gatsby+WordPress site uwalumni (2ff51eee-cdcc-4ab6-92d2-b5d2eac9190e), I have been struggling to get successful builds going on the branch “netlify”, where I’ve been making a few Netlify-specific config changes. Last night two builds failed during the deployment phase, after the build phase had successfully completed. They both showed something like this in the logs during the deployment phase:

10:42:18 PM: Deploy site
10:42:18 PM: ────────────────────────────────────────────────────────────────
10:42:18 PM: ​
10:42:19 PM: Starting to deploy site from “public”
10:42:50 PM: Calculating files to upload
10:43:11 PM: 7832 new files to upload
10:43:11 PM: 0 new functions to upload
10:43:11 PM: Starting to upload
10:43:16 PM: 10% uploaded
10:43:22 PM: 20% uploaded
10:43:25 PM: 30% uploaded
10:43:30 PM: 40% uploaded
10:43:36 PM: 50% uploaded
10:43:41 PM: 60% uploaded
10:43:47 PM: 70% uploaded
10:43:51 PM: 80% uploaded
10:43:55 PM: 90% uploaded
10:43:59 PM: 100% uploaded
10:43:59 PM: Section completed: deploying
10:44:05 PM: Finished waiting for live deploy in 5.858s
10:44:05 PM: ​
10:44:05 PM: Configuration error
10:44:05 PM: ────────────────────────────────────────────────────────────────
10:44:05 PM: ​
10:44:05 PM: Error message
10:44:05 PM: Deploy did not succeed: timed out while waiting to enter states [ready]
10:44:05 PM: ​

And in the list of deploys, the summary message for these failed deploys says
"The document exceeds maximum allowed BSON object size after serialization”

There are some additional log entries with page-specific headers:
headers:
10:44:05 PM: - for: /page-data/groups/bayarea/about/support/store/page-data.json
10:44:05 PM: values:
10:44:05 PM: Referrer-Policy: strict-origin-when-cross-origin
10:44:05 PM: cache-control: public, max-age=0, must-revalidate
10:44:05 PM: referrer-policy: same-origin
10:44:05 PM: x-content-type-options: nosniff
10:44:05 PM: x-frame-options: DENY
10:44:05 PM: x-xss-protection: 1; mode=block
…etc

I do recall seeing a message having something to do with headers being too large a few weeks ago, and I’m wondering if that has something to do with this. But I can find no info about this message, and these deploys don’t correspond to any significant code changes.

These failures both happened at about 78 minutes from the start time.

The next failed deploy after these two was a timeout at 93 minutes.

I found the header message, it is in the Post-processing section:

Header rule files are too large. Please reduce the combined size of /_headers and /netlify.toml

This seems similar to topic 1000738 but there is no direct solution posted there.

I also found a case-sensitive duplication in my headers, I was specifying Referrer-Policy and there was a separate referrer-policy (can be seen in the log snippet in my first post). That upper-case Referrer-Policy is the only custom header I’m using on all pages. I changed it to lower-case and am rebuilding now.

UPDATE: fixing the duplicate header seems to have allowed me to complete a few builds, but this afternoon I got the same message again.
Each file is getting the following headers (this is output from the “deploying” section:
3:52:07 PM: - for: /page-data/groups/bayarea/local-alumni-recognition/badger-of-the-year/page-data.json
3:52:07 PM: values:
3:52:07 PM: cache-control: public, max-age=0, must-revalidate
3:52:07 PM: referrer-policy: strict-origin-when-cross-origin
3:52:07 PM: x-content-type-options: nosniff
3:52:07 PM: x-frame-options: DENY
3:52:07 PM: x-xss-protection: 1; mode=block

The only one of those that I am customizing is “referrer-policy”, which I need in order to load fonts from typography.com.

Would really appreciate it if someone could help me out with what is going on here.

You might be interested in this issue: Gatsby Adapters causes regressions & issues with headers & redirects for NETLIFY builds on >=5.12.0 · Issue #38542 · gatsbyjs/gatsby (github.com)

1 Like

We moved the project to Vercel where we don’t have any issues with this.