{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/3333","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3333/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3333/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3333/events","html_url":"https://github.com/crystal-lang/crystal/issues/3333","id":178225203,"number":3333,"title":"memory leak","user":{"login":"kostya","id":95060,"avatar_url":"https://avatars.githubusercontent.com/u/95060?v=3","gravatar_id":"","url":"https://api.github.com/users/kostya","html_url":"https://github.com/kostya","followers_url":"https://api.github.com/users/kostya/followers","following_url":"https://api.github.com/users/kostya/following{/other_user}","gists_url":"https://api.github.com/users/kostya/gists{/gist_id}","starred_url":"https://api.github.com/users/kostya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kostya/subscriptions","organizations_url":"https://api.github.com/users/kostya/orgs","repos_url":"https://api.github.com/users/kostya/repos","events_url":"https://api.github.com/users/kostya/events{/privacy}","received_events_url":"https://api.github.com/users/kostya/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/crystal-lang/crystal/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/crystal-lang/crystal/labels/standard%20library","name":"standard library","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2016-09-21T01:52:35Z","updated_at":"2016-10-01T18:42:59Z","closed_at":null,"body":"while debugging #3332, i find memory leak with `spawn`\r\n\r\ni using such timeout function:\r\n\r\n```crystal\r\ndef with_timeout(timeout = 60.0, &block)\r\n  channel = Channel(Nil).new\r\n\r\n  spawn do\r\n    block.call\r\n    begin\r\n      channel.send(nil)\r\n    rescue Channel::ClosedError\r\n    end\r\n  end\r\n\r\n  spawn do\r\n    break_at = Time.now + timeout.seconds\r\n    loop do\r\n      sleep 1.0\r\n      break if Time.now > break_at || channel.closed?\r\n    end\r\n\r\n    unless channel.closed?\r\n      begin\r\n        channel.send(nil)\r\n      rescue Channel::ClosedError\r\n      end\r\n    end\r\n  end\r\n\r\n  channel.receive\r\n  channel.close\r\nend\r\n\r\nrequire \"http/server\"\r\n\r\nserver = HTTP::Server.new \"0.0.0.0\", 8080 do |context|\r\n  context.response.headers[\"Content-Type\"] = \"text/plain\"\r\n\r\n  str = \"\"\r\n\r\n  with_timeout do\r\n    str += \"a\" * 10000\r\n    sleep rand(0.5)\r\n  end\r\n\r\n  context.response.print(str)\r\nend\r\n\r\nspawn do\r\n  loop do\r\n    p `ps -p #{Process.pid} -o rss`\r\n    sleep 30\r\n  end\r\nend\r\n\r\nputs \"Listening on http://0.0.0.0:8080\"\r\nserver.listen\r\n```\r\n\r\nosx:\r\n\r\nab -n 50000 -c 50 http://127.0.0.1:8080/\r\nrss 695Mb\r\n\r\nif i remove with_timeout:\r\n\r\nab -n 50000 -c 50 http://127.0.0.1:8080/\r\nrss 150Mb\r\n\r\n\r\ni not see any peace of code which can leak here:\r\nbtw 150Mb also quite big."},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/250929467","html_url":"https://github.com/crystal-lang/crystal/issues/3333#issuecomment-250929467","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3333","id":250929467,"user":{"login":"asterite","id":209371,"avatar_url":"https://avatars.githubusercontent.com/u/209371?v=3","gravatar_id":"","url":"https://api.github.com/users/asterite","html_url":"https://github.com/asterite","followers_url":"https://api.github.com/users/asterite/followers","following_url":"https://api.github.com/users/asterite/following{/other_user}","gists_url":"https://api.github.com/users/asterite/gists{/gist_id}","starred_url":"https://api.github.com/users/asterite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asterite/subscriptions","organizations_url":"https://api.github.com/users/asterite/orgs","repos_url":"https://api.github.com/users/asterite/repos","events_url":"https://api.github.com/users/asterite/events{/privacy}","received_events_url":"https://api.github.com/users/asterite/received_events","type":"User","site_admin":false},"created_at":"2016-10-01T18:42:59Z","updated_at":"2016-10-01T18:42:59Z","body":"Bohem GC creates many threads, always "}}
{"actor":{"display_login":"asterite"}}