Socket.js added code to prevent error loop