{"action":"created","issue":{"url":"https://api.github.com/repos/Corvusoft/restbed/issues/62","labels_url":"https://api.github.com/repos/Corvusoft/restbed/issues/62/labels{/name}","comments_url":"https://api.github.com/repos/Corvusoft/restbed/issues/62/comments","events_url":"https://api.github.com/repos/Corvusoft/restbed/issues/62/events","html_url":"https://github.com/Corvusoft/restbed/issues/62","id":126046041,"number":62,"title":"Yield doesn't work properly,","user":{"login":"terrymah","id":203638,"avatar_url":"https://avatars.githubusercontent.com/u/203638?v=3","gravatar_id":"","url":"https://api.github.com/users/terrymah","html_url":"https://github.com/terrymah","followers_url":"https://api.github.com/users/terrymah/followers","following_url":"https://api.github.com/users/terrymah/following{/other_user}","gists_url":"https://api.github.com/users/terrymah/gists{/gist_id}","starred_url":"https://api.github.com/users/terrymah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terrymah/subscriptions","organizations_url":"https://api.github.com/users/terrymah/orgs","repos_url":"https://api.github.com/users/terrymah/repos","events_url":"https://api.github.com/users/terrymah/events{/privacy}","received_events_url":"https://api.github.com/users/terrymah/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Corvusoft/restbed/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":{"login":"ben-crowhurst","id":3715287,"avatar_url":"https://avatars.githubusercontent.com/u/3715287?v=3","gravatar_id":"","url":"https://api.github.com/users/ben-crowhurst","html_url":"https://github.com/ben-crowhurst","followers_url":"https://api.github.com/users/ben-crowhurst/followers","following_url":"https://api.github.com/users/ben-crowhurst/following{/other_user}","gists_url":"https://api.github.com/users/ben-crowhurst/gists{/gist_id}","starred_url":"https://api.github.com/users/ben-crowhurst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ben-crowhurst/subscriptions","organizations_url":"https://api.github.com/users/ben-crowhurst/orgs","repos_url":"https://api.github.com/users/ben-crowhurst/repos","events_url":"https://api.github.com/users/ben-crowhurst/events{/privacy}","received_events_url":"https://api.github.com/users/ben-crowhurst/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2016-01-11T21:57:14Z","updated_at":"2016-01-12T01:34:51Z","closed_at":null,"body":"I'm trying to write a stream of Json as a response (think searching, writing one at a time as results come in). I noticed a few things:\r\n\r\n1. It doesn't work - if I \"yield\" with a status code/headers, the connection is closed. If I \"yield\" with just a string, I get an \"invalid function call\" deep inside restbed\r\n2. If I try to close the connection via session.close after calling session.yield, a \"fatal error\" is thrown\r\n2. If the connection is closed for any reason (either from restbed by yielding, see #1, or client side), restbed crashes with a null pointer deref on some session stream the next I try to write.\r\n\r\nThe repro is pretty simple: write a multithreaded http server which responds to a request by writing out a string via session.yield(string), sleeps a bit, then loops. "},"comment":{"url":"https://api.github.com/repos/Corvusoft/restbed/issues/comments/170753967","html_url":"https://github.com/Corvusoft/restbed/issues/62#issuecomment-170753967","issue_url":"https://api.github.com/repos/Corvusoft/restbed/issues/62","id":170753967,"user":{"login":"terrymah","id":203638,"avatar_url":"https://avatars.githubusercontent.com/u/203638?v=3","gravatar_id":"","url":"https://api.github.com/users/terrymah","html_url":"https://github.com/terrymah","followers_url":"https://api.github.com/users/terrymah/followers","following_url":"https://api.github.com/users/terrymah/following{/other_user}","gists_url":"https://api.github.com/users/terrymah/gists{/gist_id}","starred_url":"https://api.github.com/users/terrymah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terrymah/subscriptions","organizations_url":"https://api.github.com/users/terrymah/orgs","repos_url":"https://api.github.com/users/terrymah/repos","events_url":"https://api.github.com/users/terrymah/events{/privacy}","received_events_url":"https://api.github.com/users/terrymah/received_events","type":"User","site_admin":false},"created_at":"2016-01-12T01:34:50Z","updated_at":"2016-01-12T01:34:50Z","body":"    void test1(std::shared_ptr<Session> session) {\r\n        session->yield(OK, \"\", { { \"Connection\", \"keep-alive\" } });\r\n\r\n        for (int i = 0; i < 5; ++i) {\r\n            session->yield(OK, \"result\", { {\"Content-length\", \"6\" }, { \"Connection\", \"keep-alive\" } });\r\n            std::this_thread::sleep_for(std::chrono::seconds(1));\r\n        }\r\n\r\n        session->close(OK, \"OK\", { { \"Connection\", \"close\" } });\r\n        printf(\"returning\");\r\n    }\r\n\r\n    void test2(std::shared_ptr<Session> session) {\r\n        session->yield(\"setup\");\r\n\r\n        for (int i = 0; i < 5; ++i) {\r\n            session->yield(\"result\");\r\n            std::this_thread::sleep_for(std::chrono::seconds(1));\r\n        }\r\n\r\n        session->close(OK, \"DONE\", { { \"Connection\", \"close\" } });\r\n        printf(\"returning\");\r\n    }\r\n\r\n    void Test()\r\n    {\r\n        Service service;\r\n        auto settings = make_shared<Settings>();\r\n        settings->set_port((short)1234);\r\n\r\n        auto r1 = make_shared<Resource>();\r\n        r1->set_path(\"/test1\");\r\n        r1->set_method_handler(\"GET\", test1);\r\n        service.publish(r1);\r\n\r\n        auto r2 = make_shared<Resource>();\r\n        r2->set_path(\"/test2\");\r\n        r2->set_method_handler(\"GET\", test2);\r\n        service.publish(r2);\r\n\r\n        service.start(settings);\r\n    }"}}