{"action":"created","comment":{"url":"https://api.github.com/repos/bgamari/ring-buffer/pulls/comments/70628359","id":70628359,"diff_hunk":"@@ -33,14 +34,14 @@ data RingState = RingState { ringFull :: !Bool, ringHead :: !Int }\n type RingM m vm a = StateT RingState (ReaderT (vm (PrimState IO) a) m)\n \n -- | Atomically perform an action with the ring\n-withRing :: (VG.Vector v a, MonadIO m)\n+withRing :: (VG.Vector v a)\n          => RingBuffer v a\n-         -> RingM m (VG.Mutable v) a r\n-         -> m r\n-withRing rb action = do\n-    s <- liftIO $ takeMVar (ringState rb)\n+         -> RingM IO (VG.Mutable v) a r\n+         -> IO r","path":"src/Data/RingBuffer.hs","position":20,"original_position":20,"commit_id":"acc5366805ba67262ab4efc5455ea2c4e6ac0e19","original_commit_id":"acc5366805ba67262ab4efc5455ea2c4e6ac0e19","user":{"login":"bgamari","id":1010174,"avatar_url":"https://avatars.githubusercontent.com/u/1010174?v=3","gravatar_id":"","url":"https://api.github.com/users/bgamari","html_url":"https://github.com/bgamari","followers_url":"https://api.github.com/users/bgamari/followers","following_url":"https://api.github.com/users/bgamari/following{/other_user}","gists_url":"https://api.github.com/users/bgamari/gists{/gist_id}","starred_url":"https://api.github.com/users/bgamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bgamari/subscriptions","organizations_url":"https://api.github.com/users/bgamari/orgs","repos_url":"https://api.github.com/users/bgamari/repos","events_url":"https://api.github.com/users/bgamari/events{/privacy}","received_events_url":"https://api.github.com/users/bgamari/received_events","type":"User","site_admin":false},"body":"Perhaps using `exception`'s `MonadMask` would be worthwhile here.","created_at":"2016-07-13T13:52:12Z","updated_at":"2016-07-13T13:52:12Z","html_url":"https://github.com/bgamari/ring-buffer/pull/2#discussion_r70628359","pull_request_url":"https://api.github.com/repos/bgamari/ring-buffer/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/bgamari/ring-buffer/pulls/comments/70628359"},"html":{"href":"https://github.com/bgamari/ring-buffer/pull/2#discussion_r70628359"},"pull_request":{"href":"https://api.github.com/repos/bgamari/ring-buffer/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/bgamari/ring-buffer/pulls/2","id":77290131,"html_url":"https://github.com/bgamari/ring-buffer/pull/2","diff_url":"https://github.com/bgamari/ring-buffer/pull/2.diff","patch_url":"https://github.com/bgamari/ring-buffer/pull/2.patch","issue_url":"https://api.github.com/repos/bgamari/ring-buffer/issues/2","number":2,"state":"open","locked":false,"title":"Be safe against asynchronous exceptions","user":{"login":"basvandijk","id":576355,"avatar_url":"https://avatars.githubusercontent.com/u/576355?v=3","gravatar_id":"","url":"https://api.github.com/users/basvandijk","html_url":"https://github.com/basvandijk","followers_url":"https://api.github.com/users/basvandijk/followers","following_url":"https://api.github.com/users/basvandijk/following{/other_user}","gists_url":"https://api.github.com/users/basvandijk/gists{/gist_id}","starred_url":"https://api.github.com/users/basvandijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basvandijk/subscriptions","organizations_url":"https://api.github.com/users/basvandijk/orgs","repos_url":"https://api.github.com/users/basvandijk/repos","events_url":"https://api.github.com/users/basvandijk/events{/privacy}","received_events_url":"https://api.github.com/users/basvandijk/received_events","type":"User","site_admin":false},"body":"Hi Ben,\r\n\r\nI would like to use your `ring-buffer` package so I did a quick code review and spotted the following:\r\n\r\n[withRing](https://github.com/bgamari/ring-buffer/blob/master/src/Data/RingBuffer.hs#L35) performs a `takeMVar` followed by the supplied action followed by a `putMVar`. What happens when an asynchronous exception gets thrown after the action but before the `putMVar`? I think we risk the vector getting out of sync with the RingState.\r\n\r\nThe simplest solution (which this PR implements) is to mask asynchronous exceptions for the whole duration of `withRing`:\r\n\r\n```haskell\r\nwithRing rb action = mask_ $ do ...\r\n```\r\n\r\n","created_at":"2016-07-13T13:38:44Z","updated_at":"2016-07-13T13:52:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"60d7a05eeabf64be05146227250c245b27e11b26","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/bgamari/ring-buffer/pulls/2/commits","review_comments_url":"https://api.github.com/repos/bgamari/ring-buffer/pulls/2/comments","review_comment_url":"https://api.github.com/repos/bgamari/ring-buffer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bgamari/ring-buffer/issues/2/comments","statuses_url":"https://api.github.com/repos/bgamari/ring-buffer/statuses/acc5366805ba67262ab4efc5455ea2c4e6ac0e19","head":{"label":"basvandijk:fix-asynchronous-exceptions","ref":"fix-asynchronous-exceptions","sha":"acc5366805ba67262ab4efc5455ea2c4e6ac0e19","user":{"login":"basvandijk","id":576355,"avatar_url":"https://avatars.githubusercontent.com/u/576355?v=3","gravatar_id":"","url":"https://api.github.com/users/basvandijk","html_url":"https://github.com/basvandijk","followers_url":"https://api.github.com/users/basvandijk/followers","following_url":"https://api.github.com/users/basvandijk/following{/other_user}","gists_url":"https://api.github.com/users/basvandijk/gists{/gist_id}","starred_url":"https://api.github.com/users/basvandijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basvandijk/subscriptions","organizations_url":"https://api.github.com/users/basvandijk/orgs","repos_url":"https://api.github.com/users/basvandijk/repos","events_url":"https://api.github.com/users/basvandijk/events{/privacy}","received_events_url":"https://api.github.com/users/basvandijk/received_events","type":"User","site_admin":false},"repo":{"id":63244243,"name":"ring-buffer","full_name":"basvandijk/ring-buffer","owner":{"login":"basvandijk","id":576355,"avatar_url":"https://avatars.githubusercontent.com/u/576355?v=3","gravatar_id":"","url":"https://api.github.com/users/basvandijk","html_url":"https://github.com/basvandijk","followers_url":"https://api.github.com/users/basvandijk/followers","following_url":"https://api.github.com/users/basvandijk/following{/other_user}","gists_url":"https://api.github.com/users/basvandijk/gists{/gist_id}","starred_url":"https://api.github.com/users/basvandijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basvandijk/subscriptions","organizations_url":"https://api.github.com/users/basvandijk/orgs","repos_url":"https://api.github.com/users/basvandijk/repos","events_url":"https://api.github.com/users/basvandijk/events{/privacy}","received_events_url":"https://api.github.com/users/basvandijk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/basvandijk/ring-buffer","description":"A concurrent mutable ring-buffer","fork":true,"url":"https://api.github.com/repos/basvandijk/ring-buffer","forks_url":"https://api.github.com/repos/basvandijk/ring-buffer/forks","keys_url":"https://api.github.com/repos/basvandijk/ring-buffer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/basvandijk/ring-buffer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/basvandijk/ring-buffer/teams","hooks_url":"https://api.github.com/repos/basvandijk/ring-buffer/hooks","issue_events_url":"https://api.github.com/repos/basvandijk/ring-buffer/issues/events{/number}","events_url":"https://api.github.com/repos/basvandijk/ring-buffer/events","assignees_url":"https://api.github.com/repos/basvandijk/ring-buffer/assignees{/user}","branches_url":"https://api.github.com/repos/basvandijk/ring-buffer/branches{/branch}","tags_url":"https://api.github.com/repos/basvandijk/ring-buffer/tags","blobs_url":"https://api.github.com/repos/basvandijk/ring-buffer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/basvandijk/ring-buffer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/basvandijk/ring-buffer/git/refs{/sha}","trees_url":"https://api.github.com/repos/basvandijk/ring-buffer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/basvandijk/ring-buffer/statuses/{sha}","languages_url":"https://api.github.com/repos/basvandijk/ring-buffer/languages","stargazers_url":"https://api.github.com/repos/basvandijk/ring-buffer/stargazers","contributors_url":"https://api.github.com/repos/basvandijk/ring-buffer/contributors","subscribers_url":"https://api.github.com/repos/basvandijk/ring-buffer/subscribers","subscription_url":"https://api.github.com/repos/basvandijk/ring-buffer/subscription","commits_url":"https://api.github.com/repos/basvandijk/ring-buffer/commits{/sha}","git_commits_url":"https://api.github.com/repos/basvandijk/ring-buffer/git/commits{/sha}","comments_url":"https://api.github.com/repos/basvandijk/ring-buffer/comments{/number}","issue_comment_url":"https://api.github.com/repos/basvandijk/ring-buffer/issues/comments{/number}","contents_url":"https://api.github.com/repos/basvandijk/ring-buffer/contents/{+path}","compare_url":"https://api.github.com/repos/basvandijk/ring-buffer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/basvandijk/ring-buffer/merges","archive_url":"https://api.github.com/repos/basvandijk/ring-buffer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/basvandijk/ring-buffer/downloads","issues_url":"https://api.github.com/repos/basvandijk/ring-buffer/issues{/number}","pulls_url":"https://api.github.com/repos/basvandijk/ring-buffer/pulls{/number}","milestones_url":"https://api.github.com/repos/basvandijk/ring-buffer/milestones{/number}","notifications_url":"https://api.github.com/repos/basvandijk/ring-buffer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/basvandijk/ring-buffer/labels{/name}","releases_url":"https://api.github.com/repos/basvandijk/ring-buffer/releases{/id}","deployments_url":"https://api.github.com/repos/basvandijk/ring-buffer/deployments","created_at":"2016-07-13T12:32:24Z","updated_at":"2016-07-13T12:32:25Z","pushed_at":"2016-07-13T13:36:21Z","git_url":"git://github.com/basvandijk/ring-buffer.git","ssh_url":"git@github.com:basvandijk/ring-buffer.git","clone_url":"https://github.com/basvandijk/ring-buffer.git","svn_url":"https://github.com/basvandijk/ring-buffer","homepage":null,"size":10,"stargazers_count":0,"watchers_count":0,"language":"Haskell","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bgamari:master","ref":"master","sha":"ebf10b7acd42f04743021fdbb88a1e4528bcde56","user":{"login":"bgamari","id":1010174,"avatar_url":"https://avatars.githubusercontent.com/u/1010174?v=3","gravatar_id":"","url":"https://api.github.com/users/bgamari","html_url":"https://github.com/bgamari","followers_url":"https://api.github.com/users/bgamari/followers","following_url":"https://api.github.com/users/bgamari/following{/other_user}","gists_url":"https://api.github.com/users/bgamari/gists{/gist_id}","starred_url":"https://api.github.com/users/bgamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bgamari/subscriptions","organizations_url":"https://api.github.com/users/bgamari/orgs","repos_url":"https://api.github.com/users/bgamari/repos","events_url":"https://api.github.com/users/bgamari/events{/privacy}","received_events_url":"https://api.github.com/users/bgamari/received_events","type":"User","site_admin":false},"repo":{"id":25797745,"name":"ring-buffer","full_name":"bgamari/ring-buffer","owner":{"login":"bgamari","id":1010174,"avatar_url":"https://avatars.githubusercontent.com/u/1010174?v=3","gravatar_id":"","url":"https://api.github.com/users/bgamari","html_url":"https://github.com/bgamari","followers_url":"https://api.github.com/users/bgamari/followers","following_url":"https://api.github.com/users/bgamari/following{/other_user}","gists_url":"https://api.github.com/users/bgamari/gists{/gist_id}","starred_url":"https://api.github.com/users/bgamari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bgamari/subscriptions","organizations_url":"https://api.github.com/users/bgamari/orgs","repos_url":"https://api.github.com/users/bgamari/repos","events_url":"https://api.github.com/users/bgamari/events{/privacy}","received_events_url":"https://api.github.com/users/bgamari/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bgamari/ring-buffer","description":"A concurrent mutable ring-buffer","fork":false,"url":"https://api.github.com/repos/bgamari/ring-buffer","forks_url":"https://api.github.com/repos/bgamari/ring-buffer/forks","keys_url":"https://api.github.com/repos/bgamari/ring-buffer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bgamari/ring-buffer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bgamari/ring-buffer/teams","hooks_url":"https://api.github.com/repos/bgamari/ring-buffer/hooks","issue_events_url":"https://api.github.com/repos/bgamari/ring-buffer/issues/events{/number}","events_url":"https://api.github.com/repos/bgamari/ring-buffer/events","assignees_url":"https://api.github.com/repos/bgamari/ring-buffer/assignees{/user}","branches_url":"https://api.github.com/repos/bgamari/ring-buffer/branches{/branch}","tags_url":"https://api.github.com/repos/bgamari/ring-buffer/tags","blobs_url":"https://api.github.com/repos/bgamari/ring-buffer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bgamari/ring-buffer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bgamari/ring-buffer/git/refs{/sha}","trees_url":"https://api.github.com/repos/bgamari/ring-buffer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bgamari/ring-buffer/statuses/{sha}","languages_url":"https://api.github.com/repos/bgamari/ring-buffer/languages","stargazers_url":"https://api.github.com/repos/bgamari/ring-buffer/stargazers","contributors_url":"https://api.github.com/repos/bgamari/ring-buffer/contributors","subscribers_url":"https://api.github.com/repos/bgamari/ring-buffer/subscribers","subscription_url":"https://api.github.com/repos/bgamari/ring-buffer/subscription","commits_url":"https://api.github.com/repos/bgamari/ring-buffer/commits{/sha}","git_commits_url":"https://api.github.com/repos/bgamari/ring-buffer/git/commits{/sha}","comments_url":"https://api.github.com/repos/bgamari/ring-buffer/comments{/number}","issue_comment_url":"https://api.github.com/repos/bgamari/ring-buffer/issues/comments{/number}","contents_url":"https://api.github.com/repos/bgamari/ring-buffer/contents/{+path}","compare_url":"https://api.github.com/repos/bgamari/ring-buffer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bgamari/ring-buffer/merges","archive_url":"https://api.github.com/repos/bgamari/ring-buffer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bgamari/ring-buffer/downloads","issues_url":"https://api.github.com/repos/bgamari/ring-buffer/issues{/number}","pulls_url":"https://api.github.com/repos/bgamari/ring-buffer/pulls{/number}","milestones_url":"https://api.github.com/repos/bgamari/ring-buffer/milestones{/number}","notifications_url":"https://api.github.com/repos/bgamari/ring-buffer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bgamari/ring-buffer/labels{/name}","releases_url":"https://api.github.com/repos/bgamari/ring-buffer/releases{/id}","deployments_url":"https://api.github.com/repos/bgamari/ring-buffer/deployments","created_at":"2014-10-27T01:11:58Z","updated_at":"2016-04-18T07:49:18Z","pushed_at":"2016-07-13T13:38:44Z","git_url":"git://github.com/bgamari/ring-buffer.git","ssh_url":"git@github.com:bgamari/ring-buffer.git","clone_url":"https://github.com/bgamari/ring-buffer.git","svn_url":"https://github.com/bgamari/ring-buffer","homepage":null,"size":10,"stargazers_count":3,"watchers_count":3,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bgamari/ring-buffer/pulls/2"},"html":{"href":"https://github.com/bgamari/ring-buffer/pull/2"},"issue":{"href":"https://api.github.com/repos/bgamari/ring-buffer/issues/2"},"comments":{"href":"https://api.github.com/repos/bgamari/ring-buffer/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/bgamari/ring-buffer/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/bgamari/ring-buffer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bgamari/ring-buffer/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/bgamari/ring-buffer/statuses/acc5366805ba67262ab4efc5455ea2c4e6ac0e19"}}}}
{"actor":{"display_login":"bgamari"}}