13

Socket.IO make an infinte loop on connection ! It's weird and never happen until now. I don't know what's wrong. I try to rebuild the package, I copy some code from an older source and the same result...

io.on('connection', function(socket){
  console.log('someone connected << infinite loop');
});

It's a basic ExpressJS server with http on top.

const
port        = process.env.PORT || 3200,
app         = require('express')(),
express     = require('express'),
mysql       = require('mysql'),
bodyParser  = require('body-parser'),
path        = require('path'),
methodOverride = require('method-override'),
http        = require('http').Server(app),
io          = require('socket.io')(http);

Client-Side

var socket = io();
Rafael Stepan
  • 660
  • 6
  • 15

2 Answers2

41

The problem was at the client-side, I don't load the latest version of socket.io like on the server-side. In my package.json I have 2.0.3 and at the client-side was 1.2.0.. For everyone who have this problem

Rafael Stepan
  • 660
  • 6
  • 15
  • 3
    Thank you. I ran into the same problem. Does anyone know how to refuse connections if the client doesn't have the proper socket io version (or any other fix for that matter)? – Altimus Prime Aug 30 '17 at 01:45
  • 2
    For the record it's actually the same library for client and server. They have a version up on Cloudflare, the current one is https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js – Brock Klein Oct 09 '17 at 21:29
  • basically 2 hours troubleshooting down the drain. Either I missed some important debug / stack trace configs, or this is just poorly implemented error logging on socket.ios end – soulshined Aug 23 '19 at 05:57
1

This happened to me when I emitted an array (on connection) and not an object...

I solved it by wrapping the array with {} so I'm now sending an object... i.e {array}...

e.g:

myArray = [{blah:"some value"},{blah2:"some other value"}];

socket.emit('target',myArray); //results in infinite loop

socket.emit('target',{myArray}); //sends ok and not looping

No need for socket version to match on server and client... in my case the client is c# and my server is node.js

urfx
  • 165
  • 1
  • 10