{"action":"created","issue":{"url":"https://api.github.com/repos/uwiger/gproc/issues/109","repository_url":"https://api.github.com/repos/uwiger/gproc","labels_url":"https://api.github.com/repos/uwiger/gproc/issues/109/labels{/name}","comments_url":"https://api.github.com/repos/uwiger/gproc/issues/109/comments","events_url":"https://api.github.com/repos/uwiger/gproc/issues/109/events","html_url":"https://github.com/uwiger/gproc/issues/109","id":145261985,"number":109,"title":"gproc_pool:claim doesn't return worker when calling process is killed","user":{"login":"netDalek","id":1823353,"avatar_url":"https://avatars.githubusercontent.com/u/1823353?v=3","gravatar_id":"","url":"https://api.github.com/users/netDalek","html_url":"https://github.com/netDalek","followers_url":"https://api.github.com/users/netDalek/followers","following_url":"https://api.github.com/users/netDalek/following{/other_user}","gists_url":"https://api.github.com/users/netDalek/gists{/gist_id}","starred_url":"https://api.github.com/users/netDalek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netDalek/subscriptions","organizations_url":"https://api.github.com/users/netDalek/orgs","repos_url":"https://api.github.com/users/netDalek/repos","events_url":"https://api.github.com/users/netDalek/events{/privacy}","received_events_url":"https://api.github.com/users/netDalek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-01T19:15:29Z","updated_at":"2016-04-03T07:45:37Z","closed_at":null,"body":"I've found gproc_pool very flexible vs other pool libraries, but found this behaviour\r\n```\r\n48>  gproc_pool:claim(pool, fun(_, P) ->  P end).\r\n{true,<0.185.0>}\r\n49> Pid = spawn_link(fun() -> gproc_pool:claim(pool, fun(_, P) -> timer:sleep(10000), P en\r\nd) end).\r\n<0.223.0>\r\n50> exit(Pid, kill).\r\n** exception exit: killed\r\n51>  gproc_pool:claim(pool, fun(_, P) ->  P end).\r\nfalse\r\n69> gproc_pool:active_workers(pool).\r\n[{a,<0.185.0>}]\r\n```\r\n\r\nAfter killing the process, worker stay busy forever. I look through the code and found that it is expected behaviour. Am I right? Are there any plans to improve it?"},"comment":{"url":"https://api.github.com/repos/uwiger/gproc/issues/comments/204901072","html_url":"https://github.com/uwiger/gproc/issues/109#issuecomment-204901072","issue_url":"https://api.github.com/repos/uwiger/gproc/issues/109","id":204901072,"user":{"login":"uwiger","id":160216,"avatar_url":"https://avatars.githubusercontent.com/u/160216?v=3","gravatar_id":"","url":"https://api.github.com/users/uwiger","html_url":"https://github.com/uwiger","followers_url":"https://api.github.com/users/uwiger/followers","following_url":"https://api.github.com/users/uwiger/following{/other_user}","gists_url":"https://api.github.com/users/uwiger/gists{/gist_id}","starred_url":"https://api.github.com/users/uwiger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uwiger/subscriptions","organizations_url":"https://api.github.com/users/uwiger/orgs","repos_url":"https://api.github.com/users/uwiger/repos","events_url":"https://api.github.com/users/uwiger/events{/privacy}","received_events_url":"https://api.github.com/users/uwiger/received_events","type":"User","site_admin":false},"created_at":"2016-04-03T07:45:37Z","updated_at":"2016-04-03T07:45:37Z","body":"Describing it to my son, I came up with some failure scenarios that seem very hard to address.\r\n\r\nBasically, the approach *is* inherently vulnerable to the calling process being murdered while running inside the claim. Starting from the (correct) assumption that the process could be killed after any given call, at least the following scenarios, however unlikely, come to mind:\r\n\r\n* Line [509](https://github.com/uwiger/gproc/blob/uw-claim-wrapper/src/gproc_pool.erl#L509), just after getting the lock, but before spawning the monitoring process. A solution could be to start monitoring before trying the lock, but this seems to forfeit the purpose of the approach.\r\n* Line [551](https://github.com/uwiger/gproc/blob/uw-claim-wrapper/src/gproc_pool.erl#L551), if the calling process is killed just after killing the monitoring process, but before resetting the counter, the counter will never be reset.\r\n* If lines 551 & 552 are switched, and the calling process resets the counter then dies before killing the monitoring process, the monitor will reset the counter again, possibly after another process has claimed it.\r\n\r\nConsidering the above, one could either conclude that the `claim()` operation is broken and shouldn't be used, or decide to live with the probability that it sometimes breaks, and then decide which types of breakage are least desirable (I'd wager that the counter never getting reset is the most serious).\r\n\r\nAlternatively, figure out a different approach that's safe and not so much slower that the function becomes unfit for its purpose."}}