⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@AbdelrahmanHafez
Copy link

@AbdelrahmanHafez AbdelrahmanHafez commented Jan 11, 2026

Fixes #61346

Solution

Add a 2MB limit to inspectValue() output in assertion_error.js. When truncation occurs:

  • A ... [truncated] marker is added to the output
  • The error message indicates lines were skipped

The assertion logic is unaffected; only the error output is truncated.

Trade-offs

If both objects produce very large inspect output and happen to match exactly in the first 2MB but differ later, the diff would appear identical. However:

  • The alternative is an OOM crash, which is worse
  • The assertion result is still correct (=== failed)
  • A truncation marker indicates output was cut off
  • Users can examine error.actual and error.expected programmatically

Alternative approaches considered

  1. Skip diff entirely for huge objects - Just show "Objects are not equal (output too large to diff)"
  2. Smarter truncation - Find where objects differ first, truncate around that area. However, this is complex and the performance benefit is unclear: for objects with exponential paths, even traversing them could be expensive, and the subtree around the difference may still contain references to shared objects.

Add a regression test for an issue where assert.strictEqual
causes OOM when comparing objects with many converging paths
to shared objects. The test creates an object graph similar
to Mongoose documents and verifies that the assertion fails
with an AssertionError rather than crashing.
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Jan 11, 2026
Objects with many converging paths to shared objects can cause
exponential growth in util.inspect output. When assert.strictEqual
fails on such objects, the error message generation would OOM while
trying to create a diff of the 100+ MB inspect strings.

Add a 2MB limit to inspectValue() output. When truncation occurs,
a marker is added and the error message indicates lines were skipped.
The comparison itself is unaffected; only the error output is truncated.
@AbdelrahmanHafez AbdelrahmanHafez changed the title test: add test for assert OOM on large object diff assert: prevent OOM when generating diff for large objects Jan 11, 2026
@AbdelrahmanHafez AbdelrahmanHafez marked this pull request as ready for review January 11, 2026 18:04
@AbdelrahmanHafez AbdelrahmanHafez force-pushed the fix/assert-strictequal-oom branch from 413a099 to 3b6e7b3 Compare January 11, 2026 18:25
@AbdelrahmanHafez AbdelrahmanHafez force-pushed the fix/assert-strictequal-oom branch from 3b6e7b3 to 8905178 Compare January 11, 2026 18:26
@AbdelrahmanHafez
Copy link
Author

@avivkeller
Could you approve the CI run to verify if something's broken? I'd like to fix any potential issues tonight if possible.

@avivkeller avivkeller added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 11, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 11, 2026
@nodejs-github-bot
Copy link
Collaborator

@AbdelrahmanHafez
Copy link
Author

I've investigated the CI failures:

GitHub Actions failures (coverage-linux, test-linux, test-tarball-linux, x86_64-linux): All terminated with exit code 143 due to runner shutdown signals, not test failures. The tests that completed before shutdown all passed.

##[error]The runner has received a shutdown signal.
##[error]Process completed with exit code 143.

Jenkins CI failures (node-test-commit-linuxone, node-test-commit-plinux, node-test-linux-linked-*): These show "tests failed" but I cannot access the logs to verify if they're related to this PR or infrastructure issues.

Could a maintainer please re-trigger CI or check the Jenkins logs? @avivkeller

// Maximum size for inspect output before truncation to prevent OOM.
// Objects with many converging paths can produce exponential growth in
// util.inspect output at high depths, leading to OOM during diff generation.
const kMaxInspectOutputLength = 2 * 1024 * 1024; // 2MB
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: split the string into chunks of 512kb and compare each chunk and combine the output. The output will not be perfect, as the combining process would sometimes be weird, while the smaller chunks should actually be much much faster to inspect in full.

Copy link
Author

Choose a reason for hiding this comment

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

Good idea, will experiment with that and compare DX, and performance for any objects that are over 512kb. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] assert.strictEqual OOM on objects with deeply shared references

4 participants