Fix stack overflow error when serializing complex object graph#331
Fix stack overflow error when serializing complex object graph#331dotnetpowered wants to merge 2 commits into
Conversation
… by getting stuck in endless loops
|
Hi Brian, The static VisitorCache is not threadsafe. Could you upload a failing test I can look at so I can have a look at an optimal way to solve this. I think it's better to have an explicit depth (as mentioned in the thread) would be better here. |
|
Hi, The VisistorCache was built to solve the thread safety issue by using the textwriter as the key. However, I didn't go far enough. I've added locking which should solve the problem. I think the explicit depth is a good idea too, but I think it still makes sense to have protection for looping regardless of the depth option. This requires no code change to existing code using the library to gain this protection. Here is the code that fails with a stackoverflow: |
|
Hi Brian, I ended up going with a configurable The I've included your test above as part of the test suite. This will be available in the next version of ServiceStack v3.9.47 that I'll try to deploy this weekend. thx for reporting. |
Track visited objects during serialization to prevent stack overflows. Prevents serializer from getting stuck in endless loops by not revisiting objects. Related to scriptcs bug: scriptcs/scriptcs#255