{"action":"created","issue":{"url":"https://api.github.com/repos/uWebSockets/uWebSockets/issues/334","repository_url":"https://api.github.com/repos/uWebSockets/uWebSockets","labels_url":"https://api.github.com/repos/uWebSockets/uWebSockets/issues/334/labels{/name}","comments_url":"https://api.github.com/repos/uWebSockets/uWebSockets/issues/334/comments","events_url":"https://api.github.com/repos/uWebSockets/uWebSockets/issues/334/events","html_url":"https://github.com/uWebSockets/uWebSockets/issues/334","id":190115535,"number":334,"title":"Server crashes when broadcasting to disconnected user.","user":{"login":"lucasterra","id":441058,"avatar_url":"https://avatars.githubusercontent.com/u/441058?v=3","gravatar_id":"","url":"https://api.github.com/users/lucasterra","html_url":"https://github.com/lucasterra","followers_url":"https://api.github.com/users/lucasterra/followers","following_url":"https://api.github.com/users/lucasterra/following{/other_user}","gists_url":"https://api.github.com/users/lucasterra/gists{/gist_id}","starred_url":"https://api.github.com/users/lucasterra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucasterra/subscriptions","organizations_url":"https://api.github.com/users/lucasterra/orgs","repos_url":"https://api.github.com/users/lucasterra/repos","events_url":"https://api.github.com/users/lucasterra/events{/privacy}","received_events_url":"https://api.github.com/users/lucasterra/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-17T17:44:06Z","updated_at":"2016-11-17T17:51:49Z","closed_at":null,"body":"**Platform/Language:** Windows (MSVC 2015, C++)\r\n**Using SSL?:** No\r\n**Problem description:**\r\nThe following code is pretty simple, it does the following: \"Prints out any users that connects\". When a user disconnects, it broadcasts to all connected users who is leaving. The problem happens when, for some reason, the server tries to send a message to a user already disconnected, it then tries to access a memory that was already erased.\r\n\r\n**Stack trace:**\r\n```\r\n \techo.exe!uS::NodeData::getSmallMemoryBlock(int index) Line 146\tC++\r\n \techo.exe!uWS::WebSocket<1>::sendPrepared(uWS::WebSocket<1>::PreparedMessage * preparedMessage, void * callbackData) Line 97\tC++\r\n \techo.exe!uWS::Group<1>::broadcast::__l2::<lambda>(uWS::WebSocket<1> ws) Line 138\tC++\r\n \techo.exe!uWS::Group<1>::forEach<void <lambda>(uWS::WebSocket<1>) >(const uWS::Group<1>::broadcast::__l2::void <lambda>(uWS::WebSocket<1>) & cb) Line 73\tC++\r\n \techo.exe!uWS::Group<1>::broadcast(const char * message, unsigned int length, uWS::OpCode opCode) Line 139\tC++\r\n \techo.exe!main::__l2::<lambda>(uWS::WebSocket<1> ws, int code, char * m, unsigned int length) Line 29\tC++\r\n \t[External Code]\t\r\n \techo.exe!uWS::WebSocket<1>::onEnd(uS::Socket s) Line 170\tC++\r\n \techo.exe!uWS::WebSocket<1>::sendPrepared(uWS::WebSocket<1>::PreparedMessage * preparedMessage, void * callbackData) Line 117\tC++\r\n \techo.exe!uWS::Group<1>::broadcast::__l2::<lambda>(uWS::WebSocket<1> ws) Line 138\tC++\r\n \techo.exe!uWS::Group<1>::forEach<void <lambda>(uWS::WebSocket<1>) >(const uWS::Group<1>::broadcast::__l2::void <lambda>(uWS::WebSocket<1>) & cb) Line 73\tC++\r\n \techo.exe!uWS::Group<1>::broadcast(const char * message, unsigned int length, uWS::OpCode opCode) Line 139\tC++\r\n \techo.exe!main::__l2::<lambda>(uWS::WebSocket<1> ws, int code, char * m, unsigned int length) Line 29\tC++\r\n \t[External Code]\t\r\n>\techo.exe!uWS::WebSocket<1>::onEnd(uS::Socket s) Line 170\tC++\r\n \techo.exe!uS::Socket::io_cb<uWS::WebSocket<1> >(uv_poll_s * p, int status, int events) Line 280\tC++\r\n```\r\n\r\n**How to reproduce:**\r\n* Run the server with the code below\r\n* Connect a few clients to the server (say 10).\r\n* Disconnect them all at the same time.\r\n\r\n**Short code:**\r\n```cpp\r\n#include <uWS.h>\r\n#include <iostream>\r\n\r\nint main() {\r\n  uWS::Hub h;\r\n\r\n  h.onConnection([&h](uWS::WebSocket<uWS::SERVER> ws, uWS::UpgradeInfo ui) {\r\n    std::cout << \"Connected: \" << (long)ws.getPollHandle() << std::endl;\r\n  });\r\n\r\n  h.onDisconnection([&h](uWS::WebSocket<uWS::SERVER> ws, int code, char* m, size_t length) {\r\n    std::cout << \"Disconnected: \" << (long)ws.getPollHandle() << std::endl;\r\n\r\n    std::string msg = \"User disconnected: \";\r\n    msg += std::to_string((size_t)ws.getPollHandle());\r\n\r\n    h.uWS::Group<uWS::SERVER>::broadcast(msg.c_str(), msg.length() + 1, uWS::TEXT);\r\n\r\n    // Print out who we will be broadcasting to.\r\n    std::cout << \"Broadcasting to: \";\r\n    h.uWS::Group<uWS::SERVER>::forEach([](uWS::WebSocket<uWS::SERVER> ws) {\r\n      std::cout << (long)ws.getPollHandle() << \" \";\r\n    });\r\n    std::cout << std::endl;\r\n  });\r\n\r\n  h.listen(8000);\r\n  h.run();\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/uWebSockets/uWebSockets/issues/comments/261318401","html_url":"https://github.com/uWebSockets/uWebSockets/issues/334#issuecomment-261318401","issue_url":"https://api.github.com/repos/uWebSockets/uWebSockets/issues/334","id":261318401,"user":{"login":"alexhultman","id":3397140,"avatar_url":"https://avatars.githubusercontent.com/u/3397140?v=3","gravatar_id":"","url":"https://api.github.com/users/alexhultman","html_url":"https://github.com/alexhultman","followers_url":"https://api.github.com/users/alexhultman/followers","following_url":"https://api.github.com/users/alexhultman/following{/other_user}","gists_url":"https://api.github.com/users/alexhultman/gists{/gist_id}","starred_url":"https://api.github.com/users/alexhultman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexhultman/subscriptions","organizations_url":"https://api.github.com/users/alexhultman/orgs","repos_url":"https://api.github.com/users/alexhultman/repos","events_url":"https://api.github.com/users/alexhultman/events{/privacy}","received_events_url":"https://api.github.com/users/alexhultman/received_events","type":"User","site_admin":false},"created_at":"2016-11-17T17:51:49Z","updated_at":"2016-11-17T17:51:49Z","body":"Yep. It's a bug, I didn't finish that forEach thing (broadcast calls forEach)."}}
{"actor":{"display_login":"alexhultman"}}