-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
assert: prevent OOM when generating diff for large objects #61347
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
Open
AbdelrahmanHafez
wants to merge
5
commits into
nodejs:main
Choose a base branch
from
AbdelrahmanHafez:fix/assert-strictequal-oom
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9132d16
test: add test for assert OOM on large object diff
AbdelrahmanHafez 5bb2cdc
assert: prevent OOM when generating diff for large objects
AbdelrahmanHafez 8905178
test: add test for assert OOM on large object diff
AbdelrahmanHafez 94f2575
assert: address review feedback
AbdelrahmanHafez 68712db
assert: address PR feedback
AbdelrahmanHafez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Flags: --max-old-space-size=512 | ||
| 'use strict'; | ||
|
|
||
| // Regression test: assert.strictEqual should not OOM when comparing objects | ||
| // with many converging paths to shared objects. Such objects cause exponential | ||
| // growth in util.inspect output, which previously led to OOM during error | ||
| // message generation. | ||
|
|
||
| require('../common'); | ||
| const assert = require('assert'); | ||
|
|
||
| // Test: should throw AssertionError, not OOM | ||
| { | ||
| const { doc1, doc2 } = createTestObjects(); | ||
|
|
||
| assert.throws( | ||
| () => assert.strictEqual(doc1, doc2), | ||
| (err) => { | ||
| assert.ok(err instanceof assert.AssertionError); | ||
| // Message should be bounded (fix truncates inspect output at 2MB) | ||
| assert.ok(err.message.length < 5 * 1024 * 1024); | ||
| return true; | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| // Creates objects where many paths converge on shared objects, causing | ||
| // exponential growth in util.inspect output at high depths. | ||
| function createTestObjects() { | ||
| const base = createBase(); | ||
|
|
||
| const s1 = createSchema(base, 's1'); | ||
| const s2 = createSchema(base, 's2'); | ||
| base.schemas.s1 = s1; | ||
| base.schemas.s2 = s2; | ||
|
|
||
| const doc1 = createDoc(s1, base); | ||
| const doc2 = createDoc(s2, base); | ||
|
|
||
| // Populated refs create additional converging paths | ||
| for (let i = 0; i < 2; i++) { | ||
| const ps = createSchema(base, 'p' + i); | ||
| base.schemas['p' + i] = ps; | ||
| doc1.$__.pop['r' + i] = { value: createDoc(ps, base), opts: { base, schema: ps } }; | ||
| } | ||
|
|
||
| // Cross-link creates more converging paths | ||
| doc1.$__.pop.r0.value.$__parent = doc2; | ||
|
|
||
| return { doc1, doc2 }; | ||
| } | ||
|
|
||
| function createBase() { | ||
| const base = { types: {}, schemas: {} }; | ||
| for (let i = 0; i < 4; i++) { | ||
| base.types['t' + i] = { | ||
| base, | ||
| caster: { base }, | ||
| opts: { base, validators: [{ base }, { base }] } | ||
| }; | ||
| } | ||
| return base; | ||
| } | ||
|
|
||
| function createSchema(base, name) { | ||
| const schema = { name, base, paths: {}, children: [] }; | ||
| for (let i = 0; i < 6; i++) { | ||
| schema.paths['f' + i] = { | ||
| schema, base, | ||
| type: base.types['t' + (i % 4)], | ||
| caster: base.types['t' + (i % 4)].caster, | ||
| opts: { schema, base, validators: [{ schema, base }] } | ||
| }; | ||
| } | ||
| for (let i = 0; i < 2; i++) { | ||
| const child = { name: name + '_c' + i, base, parent: schema, paths: {} }; | ||
| for (let j = 0; j < 3; j++) { | ||
| child.paths['cf' + j] = { schema: child, base, type: base.types['t' + (j % 4)] }; | ||
| } | ||
| schema.children.push(child); | ||
| } | ||
| return schema; | ||
| } | ||
|
|
||
| function createDoc(schema, base) { | ||
| const doc = { schema, base, $__: { scopes: {}, pop: {} } }; | ||
| for (let i = 0; i < 6; i++) { | ||
| doc.$__.scopes['p' + i] = { schema, base, type: base.types['t' + (i % 4)] }; | ||
| } | ||
| return doc; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.