{"action":"created","issue":{"url":"https://api.github.com/repos/mpenet/jet/issues/29","labels_url":"https://api.github.com/repos/mpenet/jet/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/mpenet/jet/issues/29/comments","events_url":"https://api.github.com/repos/mpenet/jet/issues/29/events","html_url":"https://github.com/mpenet/jet/issues/29","id":124685633,"number":29,"title":"thread leakage?","user":{"login":"nicferrier","id":245513,"avatar_url":"https://avatars.githubusercontent.com/u/245513?v=3","gravatar_id":"","url":"https://api.github.com/users/nicferrier","html_url":"https://github.com/nicferrier","followers_url":"https://api.github.com/users/nicferrier/followers","following_url":"https://api.github.com/users/nicferrier/following{/other_user}","gists_url":"https://api.github.com/users/nicferrier/gists{/gist_id}","starred_url":"https://api.github.com/users/nicferrier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicferrier/subscriptions","organizations_url":"https://api.github.com/users/nicferrier/orgs","repos_url":"https://api.github.com/users/nicferrier/repos","events_url":"https://api.github.com/users/nicferrier/events{/privacy}","received_events_url":"https://api.github.com/users/nicferrier/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-01-04T02:03:36Z","updated_at":"2016-01-12T07:26:50Z","closed_at":null,"body":"I'm writing something quite complex with jet and I'm getting quite serious thread leakage. About 100 threads across a particular test run.\r\n\r\nI tried to make a simple thing to see whether that suffered thread leakage and it did! Here it is:\r\n\r\n```\r\n(defn fake-jetty-handlers []\r\n  [(fn [{:keys [in out ctrl ws] :as opts}]\r\n     (timbre/debug \"fake-jetty-handlers ws-request\" (:uri opts))\r\n     (a/go-loop [data (a/<! in)]\r\n       (a/>! out (str/upper-case data))))\r\n   (fn [request-msg]\r\n     (timbre/debug \"fake-jetty-handlers http-request\" (:uri request-msg))\r\n     {:status 200\r\n      :header {:content-type \"text/html\"}\r\n      :body (format \"<h1>%s</h1>\" (str/upper-case (:uri request-msg)))})])\r\n\r\n(defn test-fake-jetty-server []\r\n  (-init-logging true)\r\n  (let [[ws-handler http-handler] (fake-jetty-handlers)\r\n        server (jet/run-jetty\r\n                {:port 8020\r\n                 :join? false\r\n                 :websocket-handler ws-handler\r\n                 :ring-handler http-handler})\r\n        client (http/client)]\r\n    (threads-log)\r\n    (async-do-then\r\n     100\r\n     ;; First an HTTP request ...\r\n     (let [con-ch (http/get client \"http://localhost:8020/blah/blah\")\r\n           response (a/<! con-ch)\r\n           body-ch (:body response)\r\n           body (a/<! body-ch)]\r\n       (threads-log)\r\n       ;; ... and then a WS request\r\n       (websoc/connect!\r\n        \"ws://localhost:8020/blah2\"\r\n        (fn [{:keys [in out ctrl ws]}]\r\n          (threads-log)\r\n          (a/go\r\n            (threads-log)\r\n            (a/>! out \"some data\")\r\n            (let [raw-in (a/<! in)]\r\n              (RETURN [body raw-in]))))))\r\n     (then\r\n      (threads-log)\r\n      (.stop server)\r\n      (threads-log)\r\n      (let [[body ws-sent] (RECV)]\r\n        (timbre/debug \"test-fake-jetty> body-response is\" body)\r\n        (timbre/debug \"test-fake-jetty> raw-response is\" ws-sent)\r\n        (assert (= ws-sent \"SOME DATA\"))\r\n        (assert (= body \"<h1>/BLAH/BLAH</h1>\"))\r\n        (threads-log))))))\r\n```\r\n\r\nHopefully that makes sense... when I run it I get a leakage of 2 threads.\r\n\r\nAnyone else come across this? Is there a good way to debug it?\r\n\r\nHere's the results of a run:\r\n\r\n```\r\n2016-01-04 09:57:33.824:INFO:oejs.Server:nREPL-worker-5: jetty-9.3.6.v20151106\r\n2016-01-04 09:57:33.839:INFO:oejs.ServerConnector:nREPL-worker-5: Started ServerConnector@a7f7d{HTTP/1.1,[http/1.1]}{0.0.0.0:8020}\r\n2016-01-04 09:57:33.840:INFO:oejs.Server:nREPL-worker-5: Started @549761ms\r\n[09:57:33] fake-jetty-handlers http-request /blah/blah\r\n[09:57:33] threadcount: 580\r\n[09:57:33] threadcount: 582\r\n[09:57:33] fake-jetty-handlers ws-request /blah2\r\n[09:57:33] threadcount: 591\r\n[09:57:33] threadcount: 591\r\n[09:57:33] threadcount: 591\r\n2016-01-04 09:57:33.910:INFO:oejs.ServerConnector:nREPL-worker-5: Stopped ServerConnector@a7f7d{HTTP/1.1,[http/1.1]}{0.0.0.0:8020}\r\n[09:57:33] threadcount: 582\r\n[09:57:33] test-fake-jetty> body-response is <h1>/BLAH/BLAH</h1>\r\n[09:57:33] test-fake-jetty> raw-response is SOME DATA\r\n[09:57:33] threadcount: 582\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/mpenet/jet/issues/comments/170822630","html_url":"https://github.com/mpenet/jet/issues/29#issuecomment-170822630","issue_url":"https://api.github.com/repos/mpenet/jet/issues/29","id":170822630,"user":{"login":"nicferrier","id":245513,"avatar_url":"https://avatars.githubusercontent.com/u/245513?v=3","gravatar_id":"","url":"https://api.github.com/users/nicferrier","html_url":"https://github.com/nicferrier","followers_url":"https://api.github.com/users/nicferrier/followers","following_url":"https://api.github.com/users/nicferrier/following{/other_user}","gists_url":"https://api.github.com/users/nicferrier/gists{/gist_id}","starred_url":"https://api.github.com/users/nicferrier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicferrier/subscriptions","organizations_url":"https://api.github.com/users/nicferrier/orgs","repos_url":"https://api.github.com/users/nicferrier/repos","events_url":"https://api.github.com/users/nicferrier/events{/privacy}","received_events_url":"https://api.github.com/users/nicferrier/received_events","type":"User","site_admin":false},"created_at":"2016-01-12T07:26:50Z","updated_at":"2016-01-12T07:26:50Z","body":"Nothing yet. I have rewritten a lot of my code to not use mult/tap - I am still getting thread leaks though but only a few. Seems like a manageable thing to track down. I'll be on it this week at some point."}}