You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Intermittent build failure: off-by-one in shuffle adds undefined to the partner list #9321
An off-by-one in shuffle can put undefined in the weighted partner list, which fails the build while prerendering /en:
Error occurred prerendering page "/en".
TypeError: Cannot read properties of undefined (reading 'id')
at components/Common/Partners/index.tsx:35:37
The shuffle seed changes every 5 minutes, so the failure depends on when the build runs, not on the code being built. It looks like a random CI failure, and re-running the job clears it once the seed has moved on.
When the hash byte is 255, randomValue is exactly 1, so j is i + 1. On the first pass of the loop, i is the last index, so j is one past the end of the array and undefined gets swapped in.
generatePartners keeps that undefined in its result, and renderSmallPartner then reads partner.id from it.
For both, running the current shuffle with that commit's partner data gives undefined for the seed at the error time, and doesn't for the seed just before it. Neither commit touches this code, and the failures on two different operating systems show it isn't platform-specific.
These two came from searching the logs of the 100 most recent failed Build runs, so there may be others.
How often
generatePartners uses Math.floor(Date.now() / 300000) as the seed. With the current 20-entry weighted list, 83 of the 20,000 most recent seeds produce undefined (0.41%), which is one 5-minute window about every 20 hours. That matches the expected 1 in 256 chance of the byte being 255.
Reproduce
Run the current shuffle with a 20-entry array and seed 5979951. The result contains undefined.
util/__tests__ has no test file for array, so a regression test using one of the seeds above would be worthwhile.
Not yet checked
The homepage and download pages use sort="weight". Whether deployed pages can also hit this at request time, rather than only during a build, hasn't been investigated.
Activity
fix(partners): keep shuffle index in bounds
test(partners): reproduce time-dependent undefined partner
fix(partners): keep shuffle index in bounds
fix(partners): keep shuffle index in bounds (nodejs#9322)