-
Notifications
You must be signed in to change notification settings - Fork 211
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
Handle circular references in custom data #990
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for the context on the bug.
Hi @waltjones and @cyrusradfar, Thanks for this, I'm the OP on the #955. I recently updated to this version in a staging environment of a node web service (running nsolid), and I've noticed some lockups at the same time that a rollbar error call is made. nsolid reports long blocking times in rollbar's
I don't have perfectly definitive repro yet, but I suspect some type of infinite loop condition. I'm going to try to narrow things down in the coming days, but I wanted to let you know sooner than later. It may not be the best idea to publish this into an npm version yet... Update: After reverting my staging environment to use an older version of rollbar.js that doesn't have the changes from this PR, I can confirm that the locking up issue hasn't occurred again. I therefore very strongly suspect that this PR's changes is what was causing the lockup. I proposed some ideas of what this could be and how to perhaps fix it here - #991 In lieu of trying some of those potential fixes, I think rollbar.js was probably better off reverting this PR and living with the original issue (#955) than it is now... |
* fix: handle circular references in custom data * test: use deepStrictEqual to compare objects for equality
Description of the change
This PR guards against circular references in user data (e.g. custom data object) by cloning the data and removing the circular references.
Why is this necessary?
The linked issue report (#955) notes that the merge function in Rollbar.js errors on the circular references. But JSON serialization will also fail, even if it didn't fail during merge. The circular reference causes an infinite traversal and stack overflow.
Why can't this be solved within the merge function?
That's the first solution I considered. It would have had the advantage of adding circular reference protection everywhere merge is used. However, merge doesn't traverse arrays (except the root, if it is an array), and adding array traversal would change its existing behavior. If there are circular references behind an array, merge will succeed, but JSON serialization will fail.
Why use deepStrictEqual in the node.js tests?
assert.equal
, as was previously used for those tests, asserts an identical object reference, not exactly equal objects. Now that the code path clones the user data, the previous assert fails. As a side note, most cases ofassert.equal
in the node.js tests should really beassert.deepStrictEqual
.Type of change
Related issues
Fixes #955
Development
Code review