{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/25536","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/25536/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/25536/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/25536/events","html_url":"https://github.com/dart-lang/sdk/issues/25536","id":127589382,"number":25536,"title":"WebSocket can send and receive messages despite being closed","user":{"login":"nex3","id":188,"avatar_url":"https://avatars0.githubusercontent.com/u/188?v=4","gravatar_id":"","url":"https://api.github.com/users/nex3","html_url":"https://github.com/nex3","followers_url":"https://api.github.com/users/nex3/followers","following_url":"https://api.github.com/users/nex3/following{/other_user}","gists_url":"https://api.github.com/users/nex3/gists{/gist_id}","starred_url":"https://api.github.com/users/nex3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nex3/subscriptions","organizations_url":"https://api.github.com/users/nex3/orgs","repos_url":"https://api.github.com/users/nex3/repos","events_url":"https://api.github.com/users/nex3/events{/privacy}","received_events_url":"https://api.github.com/users/nex3/received_events","type":"User","site_admin":false},"labels":[{"id":334529063,"url":"https://api.github.com/repos/dart-lang/sdk/labels/Type:%20bug","name":"Type: bug","color":"ededed","default":false},{"id":219928184,"url":"https://api.github.com/repos/dart-lang/sdk/labels/area-library","name":"area-library","color":"c7def8","default":false},{"id":219928199,"url":"https://api.github.com/repos/dart-lang/sdk/labels/library-io","name":"library-io","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-01-20T02:21:46Z","updated_at":"2018-04-26T13:43:09Z","closed_at":null,"author_association":"MEMBER","body":"If a WebSocket client's connection is closed by the server after its subscription has been canceled, it's still able to send messages. I haven't read the spec or examined the protocol-level interactions in detail, but this seems wrong.\n\nWhat's more, Dart's WebSocket server will also receive this message—despite having called both `WebSocket.close()` and `HttpServer.close()`. This is clearly wrong, since the documentation of `WebSocket.close()` says that it \"closes the WebSocket connection\".\n\nHere's a reproduction:\n\n``` dart\nimport 'dart:async';\nimport 'dart:io';\n\nmain() async {\n  var server = await HttpServer.bind('localhost', 0);\n  server.transform(new WebSocketTransformer()).listen((socket) {\n    socket.listen((msg) {\n      print(\"got $msg\");\n\n      // As soon as the server's socket receives a message, close the server and\n      // the socket. Once these complete there should be no server-side sockets\n      // open at all.\n      socket.close().then((_) => print(\"socket closed\"));\n      server.close().then((_) => print(\"server closed\"));\n    });\n  });\n\n  var ws = await WebSocket.connect('ws://localhost:${server.port}');\n\n  // Create and cancel a subscription.\n  ws.listen(null).cancel();\n\n  // Send a message to the server that will cause it to close the WebSocket\n  // connection.\n  ws.add(\"foo\");\n\n  // Give the server time to shut down.\n  await new Future.delayed(new Duration(seconds: 1));\n\n  // Try to send another message.\n  ws.add(\"bar\");\n}\n```\n\nI reproduced this as of 77101d63e3c661957b7829dd96d6b4324da0e768.\n\nI'd expect the socket to continue listening to the server behind-the-scenes even after the subscription is cancelled, so that it can determine when the connection is closed.\n"},"comment":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/comments/384645485","html_url":"https://github.com/dart-lang/sdk/issues/25536#issuecomment-384645485","issue_url":"https://api.github.com/repos/dart-lang/sdk/issues/25536","id":384645485,"user":{"login":"NatoBoram","id":10495562,"avatar_url":"https://avatars0.githubusercontent.com/u/10495562?v=4","gravatar_id":"","url":"https://api.github.com/users/NatoBoram","html_url":"https://github.com/NatoBoram","followers_url":"https://api.github.com/users/NatoBoram/followers","following_url":"https://api.github.com/users/NatoBoram/following{/other_user}","gists_url":"https://api.github.com/users/NatoBoram/gists{/gist_id}","starred_url":"https://api.github.com/users/NatoBoram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NatoBoram/subscriptions","organizations_url":"https://api.github.com/users/NatoBoram/orgs","repos_url":"https://api.github.com/users/NatoBoram/repos","events_url":"https://api.github.com/users/NatoBoram/events{/privacy}","received_events_url":"https://api.github.com/users/NatoBoram/received_events","type":"User","site_admin":false},"created_at":"2018-04-26T13:43:09Z","updated_at":"2018-04-26T13:43:09Z","author_association":"NONE","body":"I can confirm. Moreover, `WebSocket.readyState` always returns `WebSocket.OPEN`. https://github.com/dart-lang/sdk/issues/32876"}}
{"actor":{"display_login":"NatoBoram"}}