Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #1093

Closed
xdenser opened this issue Nov 30, 2012 · 6 comments
Closed

Memory leak #1093

xdenser opened this issue Nov 30, 2012 · 6 comments

Comments

@xdenser
Copy link

xdenser commented Nov 30, 2012

Very simple code. SIngle connection eats memory.
Node 0.8.14. Socket..io 0.9.10

Server:

var 
  io = require('socket.io').listen(3000,{
      transports:[
         'websocket',
         'htmlfile',
         'xhr-polling',
         'jsonp-polling'
       ]
  });

io.sockets.on('connection',function(socket){

  socket.on('ping',function(){
       socket.emit('pong');
  });

});

Client:

<head>
 <script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost:3000');

  function ping(){
     socket.emit('ping');
  } 
  socket.on('pong',ping);
  ping();
</script>

Tested under Windows. Run server, run client - see in task manager how node.exe eats memory.
Comment transports in server. Websocket and jsonp-polling leak. xhr-polling - does not.

@xdenser
Copy link
Author

xdenser commented Nov 30, 2012

Though looks like in 0.8.12/0.9.11 it does not.
Will test again 0.8.14/0.9.11.

@xdenser
Copy link
Author

xdenser commented Nov 30, 2012

Today it does not leak even in 0.8.14/0.9.10 . What was that yesterday ?! Closing this

@xdenser xdenser closed this as completed Nov 30, 2012
@xdenser
Copy link
Author

xdenser commented Nov 30, 2012

In fact it leaks that way:
Server

var 
  io = require('socket.io').listen(3000,{
      transports:[
         'websocket',
         'htmlfile',
         'xhr-polling',
         'jsonp-polling'
       ]
  });

io.sockets.on('connection',function(socket){

  socket.on('ping',function(data,cb){

         socket.emit('pong',function(){ });
         if(cb) cb();
  });

});

Client

<head>
 <script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost:3000');

  function ping(data,cb){
     socket.emit('ping',function(){

     });
     if(cb) cb();
  } 
  socket.on('pong',ping);
  ping();
</script>

So with ack callbacks it leaks. And I can not find in source where socket.acks are cleared.
Acks are called in 'SocketNamespace.prototype.handlePacket' in line 318
So ... #1094

@xdenser xdenser reopened this Nov 30, 2012
@3rd-Eden
Copy link
Contributor

Does your supplied fix in #1094 resolve this issue?

@xdenser
Copy link
Author

xdenser commented Nov 30, 2012

No it does not.

@xdenser
Copy link
Author

xdenser commented Nov 30, 2012

But with that variant it does:
Server

var 
  io = require('socket.io').listen(3000,{
      transports:[
         'websocket',
         'htmlfile',
         'xhr-polling',
         'jsonp-polling'
       ]
  });

io.sockets.on('connection',function(socket){

  socket.on('ping',function(cb){

         if(cb) cb();

        socket.emit('pong',function(err){ });

  });

});

client

<head>
 <script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost:3000');

  function ping(cb){
     socket.emit('ping',function(){

     });
     if(cb) cb();
  } 
  socket.on('pong',ping);
  ping();
</script>

the problem is in client if you pass callback with no arguments on server
client wiill never respond with ack. so ack never be deleted.

So somebody should decide:
which pull request to accept

either
#1096
or
socketio/socket.io-client#500

and
#1094 should be applied too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants