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

Sockets accept data even after being closed #1220

Closed
gfwilliams opened this issue Aug 17, 2017 · 0 comments
Closed

Sockets accept data even after being closed #1220

gfwilliams opened this issue Aug 17, 2017 · 0 comments

Comments

@gfwilliams
Copy link
Member

Try this, connect to localhost:8080, and then disconnect. Memory usage grows rapidly.

console.log("Connected to Wifi");
var page = '<html><body><script>var ws;setTimeout(function(){';
page += 'ws = new WebSocket("ws://" + location.host + "/my_websocket", "protocolOne");';
page += 'ws.onmessage = function (event) { console.log("MSG:"+event.data); };';
page += 'setTimeout(function() { ws.send("Hello to Espruino!"); }, 2000);';
page += '},2000);</script></body></html>';
var onPageRequest = function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end(page);
};
var server = require('ws').createServer(onPageRequest);
server.listen(8000);
server.on("websocket", function(ws) {
  var count = 0;
  console.log("Connection upgraded");
  ws.on('message',function(msg) {
    console.log("Message received");
    print("[WS] "+JSON.stringify(msg));
  });
/*  ws.on('close',function(msg) {
    if (intr) clearInterval(intr);
  });*/
  var intr = setInterval(function() {
    ws.send("Hello "+count++);
  }, 100);
});
setInterval(function() {
  console.log("Memory usage:", process.memory().usage);
}, 1000);

We should probably just throw an exception.

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

1 participant