#20 Dealing with Circular references
- Aaron
- Dec 14, 2020
- 1 min read
Updated: Dec 16, 2020
I encountered some server crashes while testing my application.
First I had to actually figure out where my error kept coming from.
The server crashed and gave this error.
hasBinary(obj, toJSON) (RangeError: Maximum call stack size exceeded)
I found this when searching for that specific error online:
Basically, my object had a property that referenced its own. Socket.io stringifies your objects when you send them, and you cannot stringify Circular references. This would make the entire server crash.

I had to rewrite quite a bit of code:
I fixed it by not referencing the entire object, but just a property (like the name of the room). If I would need to access the 'connectedRoom' of that object I would just use the name property to search for it in my global rooms object. (rooms[lastUserWhoPlayed.connectedRoom])
Commentaires