-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Some kind of crazy recursion going on in my production servers -_- #10
Comments
Whoa, crazy. I assume you're using the current version of I have very little to go on without seeing the data you're pushing through, but my best guess is at some point you have two objects that look like a pair of arrays ( Can you figure out precisely what pair of objects triggers this error, and paste them here? |
I do have an object with dimensions (length, width, height). |
This didn't bomb out though. |
Those objects are probably what's breaking it. The width / height properties are unimportant. What kinds of values does length have? Is it ever undefined / null / not a number? And apparently that object with the weird length property is responding |
|
Straight out of Chrome's console. |
Yes, that's all what I would expect, but I take it your production data on your production servers is different, which is why these don't bomb out, and your production data does. For example, I'm not sure if anybody still uses |
I use Mongoose. -_- |
Don't remind me. |
Give me a second. I'll query from Mongoose into this thing. I thought the lean call turns all of their bullshit off... |
Well there you go. You're gonna need to call I've been there, and mongoose isn't worth it. (MongoDB isn't worth it, either, but one step at a time.) |
I tried to move over to Postgres. Trust me. |
Doesn't cause it. -_- |
|
According to the documentation, the .lean() I already call keeps it a plain Object, so that isn't it. |
I found it.
Outputs
Then goes crazy. |
Wait, I'm wrong? |
Yeah, that's not it. Sorry. |
I found it. It has to do to when both the new and old objects are equal. I will paste now. |
Unfortunately, |
Ah, it is probably comparing the ObjectId() returned... |
I did
and right before the stack, it is doing
(you can tell that is the ObjectId because it doesn't print wrapped in single quotes, kill me) and then
until it exceeds the maximum call stack size. |
Even with the stringify/parse code to convert everything to plain objects. |
I'm not sure what I'm supposed to gather from the GC stacktrace. Regarding the comment before that, it seems lean() or whatever is lying to you, as including an ObjectId instance isn't what I would consider a plain old javascript object (aka. 'POJO'). If you really want to see what's going wrong, stick a I can't fix mongoose for you, but I'll look into adding a secondary check so that even if an object purports to be an Array, but has an invalid length, it won't overflow the stack. |
The error still happens even after this:
I am working on getting you test data now. |
Excellent. If you can get createPatch to break on JSON.parse output, I'll be glad to fix it. |
Do you know if this behaves well with lots of objects? Like, 10k objects, each having arrays and objects within them? I think that might be the issue. |
If you're worried about load, try it out with 10k of your objects, and see if it runs fast enough for you. If not, you can keep looking or do some profiling. Up to you. |
I can't get any meaningful output out of the |
Ah, okay, then cut it down to just |
The old and new elements are equal. There are 1,006 elements. A test element looks like this:
i is creeping up to over 250 Is this normal? |
For what it is worth, the package jsondiffpatch currently handles this data fine (and in under 100ms) I'm moving off of it because my users experience intermittent issues that I assume have to be related to the patch protocol. |
|
Just published v1.2.0, which shouldn't stack overflow even when you give it weird mongoose objects, but since I never got a replicable test case from you, I haven't been able to test that. I also generated an array of pretty complex 1K objects via http://www.json-generator.com/, and mucked around with making a few changes to a copy of the array, trying to get If you can come up with a breaking test case that has the following form, I'll fix it:
Otherwise I'm going to consider this issue closed / fixed, because I can't infer what's going wrong from your stack traces. |
How long did it take to generate the patch for the large test, approximately? |
It didn't trigger mocha's "slow test" warning, so, < 75ms. |
Could it have been that my input and output were equal? Could it have anything to do with a common key like _id and their sorted order? I will try to provide more information. |
I tried that (along with other mutations). Using 1k_array.json, the test below runs and passes in < 75ms.
|
I'm able to get it to recreate but the stringified JSON is 24mb containing sensitive data.
Where would you like me to add debugging information? |
If I turn off that console.log, I get this
|
Any reason you roll |
The test data is an array of objects with a length of 38,350. I wish I didn't have data this disgusting, trust me. If I slice it to the first 8,500, it takes 288ms but does not overflow (which is faster than jsondiffpatch). At around a length of around 9,000 for input and output, the overflows start (plain JSON.parsed objects). The expected patch should be []. |
Alright, this really isn't an error with this library at all. I ran Nasty as hell. Is there anything that can be done? Would any abuse of Promises combined with setTimeout(..., 0) or setImmediate or process.nextTick aid? |
I have an idea for a way to transform the recursive So if you want a quick and sure solution, I'd recommend defining your own |
Thanks for the response. The arrays will not be equal. They can have elements removed, added, or any field (which can also be an array of objects, yada yada) changed. It's the client side database for a SPA that I patch on any changes. I've gotten this to pass my local tests, but as soon as I put it under any real load, I have to roll back to jsondiffpatch. Please follow up with any progress you make. I am happy to help in any way possible. |
jsondiffpatch failed me and now this...
The text was updated successfully, but these errors were encountered: