Skip to content

Memory Leak when handling WebSocket at server side #27414

@jimmyshiau

Description

@jimmyshiau

Simple test case

import "dart:io";
import "dart:async";

void main() {
  HttpServer
  .bind(InternetAddress.ANY_IP_V4, 8081)
  .then((server) {
    server.autoCompress = true;
    server.listen((HttpRequest request) async {
      if (request.uri.path == "/q") {
        await socket(request);
      } else {
        request
        ..response.headers.contentType = ContentType.HTML
        ..response.write('<html><body>Hello, world!'
          '<script type="text/javascript">'
          'var ws = new WebSocket("ws://"+window.location.host+"/q");'
          'ws.onopen = function() {console.log("open");};'
          '</script>'
          '</body></html>');
      }
      request.response.close();
    });
  });
}

Future socket(HttpRequest request) async {
  return WebSocketTransformer.upgrade(request)
  .then(handleWebSocket);
}


void handleWebSocket(WebSocket socket){
  print('handleWebSocket');
  socket.listen(_onSocketData, onDone: _onSocketDone);
}

void _onSocketData(data) {print(data);}
void _onSocketDone() {print('_onSocketDone');}

Server RES

66080
133060
147224
193972
193932
224692
245348
256536
278660
259632
261072
281472
261316
263444
266912
266896
287424
287484
288996
304852
345812
347388
358788
screen shot 2016-09-22 at 11 49 33 am

At each run, I opened 100 browser tabs and then close them all. Also, before checking memory use, I ran GC first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-iotype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions