{"action":"created","comment":{"url":"https://api.github.com/repos/postmates/pycernan/pulls/comments/233905846","pull_request_review_id":175428188,"id":233905846,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMzkwNTg0Ng==","diff_hunk":"@@ -1,47 +1,126 @@\n \"\"\"\n     Base Avro client from which all other clients derive.\n \"\"\"\n+import contextlib\n import socket\n \n import pycernan.avro.config\n \n from abc import ABCMeta, abstractmethod\n+from queue import Queue, Empty\n \n-from pycernan.avro.exceptions import EmptyBatchException\n+from pycernan.avro.exceptions import EmptyBatchException, EmptyPoolException\n from pycernan.avro.serde import serialize\n \n \n+_DefunctConnection = object()\n+\n+\n+class TCPConnectionPool(object):\n+    \"\"\"\n+    Fork friendly TCP connection pool.\n+\n+    Adapted from: https://github.com/gevent/gevent/blob/master/examples/psycopg2_pool.py\n+    \"\"\"\n+    def __init__(self, host, port, maxsize, connect_timeout, read_timeout):\n+        if maxsize <= 0:\n+            raise ValueError(\"maxsize must be > 0\")\n+\n+        self.host = host\n+        self.port = port\n+        self.size = 0","path":"pycernan/avro/client.py","position":null,"original_position":32,"commit_id":"d320ab6b8aea62b325bdf8f574cf9a526ec9ba2f","original_commit_id":"2ebfad44b4607f4b273215d2c0a25695ac01e32e","user":{"login":"pulltab","id":6842323,"node_id":"MDQ6VXNlcjY4NDIzMjM=","avatar_url":"https://avatars3.githubusercontent.com/u/6842323?v=4","gravatar_id":"","url":"https://api.github.com/users/pulltab","html_url":"https://github.com/pulltab","followers_url":"https://api.github.com/users/pulltab/followers","following_url":"https://api.github.com/users/pulltab/following{/other_user}","gists_url":"https://api.github.com/users/pulltab/gists{/gist_id}","starred_url":"https://api.github.com/users/pulltab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulltab/subscriptions","organizations_url":"https://api.github.com/users/pulltab/orgs","repos_url":"https://api.github.com/users/pulltab/repos","events_url":"https://api.github.com/users/pulltab/events{/privacy}","received_events_url":"https://api.github.com/users/pulltab/received_events","type":"User","site_admin":false},"body":"Removed.","created_at":"2018-11-15T16:07:03Z","updated_at":"2018-11-15T16:07:04Z","html_url":"https://github.com/postmates/pycernan/pull/31#discussion_r233905846","pull_request_url":"https://api.github.com/repos/postmates/pycernan/pulls/31","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/postmates/pycernan/pulls/comments/233905846"},"html":{"href":"https://github.com/postmates/pycernan/pull/31#discussion_r233905846"},"pull_request":{"href":"https://api.github.com/repos/postmates/pycernan/pulls/31"}},"in_reply_to_id":233675879},"pull_request":{"url":"https://api.github.com/repos/postmates/pycernan/pulls/31","id":230280045,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMwMjgwMDQ1","html_url":"https://github.com/postmates/pycernan/pull/31","diff_url":"https://github.com/postmates/pycernan/pull/31.diff","patch_url":"https://github.com/postmates/pycernan/pull/31.patch","issue_url":"https://api.github.com/repos/postmates/pycernan/issues/31","number":31,"state":"open","locked":false,"title":"Add TCPConnectionPool to avro.Client.","user":{"login":"pulltab","id":6842323,"node_id":"MDQ6VXNlcjY4NDIzMjM=","avatar_url":"https://avatars3.githubusercontent.com/u/6842323?v=4","gravatar_id":"","url":"https://api.github.com/users/pulltab","html_url":"https://github.com/pulltab","followers_url":"https://api.github.com/users/pulltab/followers","following_url":"https://api.github.com/users/pulltab/following{/other_user}","gists_url":"https://api.github.com/users/pulltab/gists{/gist_id}","starred_url":"https://api.github.com/users/pulltab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulltab/subscriptions","organizations_url":"https://api.github.com/users/pulltab/orgs","repos_url":"https://api.github.com/users/pulltab/repos","events_url":"https://api.github.com/users/pulltab/events{/privacy}","received_events_url":"https://api.github.com/users/pulltab/received_events","type":"User","site_admin":false},"body":"Existing socket abstractions in pycernan.avro do not provide any level\r\nof isolation for callers.  In practice this translates to a single\r\ntimeout, for example, resulting in subsequent publishers receiving acks\r\nout of order when a Client is reused without first being reconstructed.\r\n\r\nRather than forcing users to think about this and to make it easier for\r\nusers to take advantage of connection level threading within Cernan, we\r\nintroduce a connection pool to avro.Client which has the following properties:\r\n\r\n* Fork-safe as long as the Client isn't used prior to forking.\r\n\r\n* Established connections are preferred over establishing new\r\nconnections.\r\n\r\n* Exceptions (on connect or during publication) are re-raised back to\r\nthe caller.\r\n\r\n* Whenever a pool connection experiences an Exception, either operational\r\nor specific to Cernan's wire protocol, the connection will be\r\nre-established in a lazy fashion.  That is, on the next operation\r\nassigned to that socket.","created_at":"2018-11-12T21:53:16Z","updated_at":"2018-11-15T16:07:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f51491f48f0edeea95e2f8aa35977642ba231083","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/postmates/pycernan/pulls/31/commits","review_comments_url":"https://api.github.com/repos/postmates/pycernan/pulls/31/comments","review_comment_url":"https://api.github.com/repos/postmates/pycernan/pulls/comments{/number}","comments_url":"https://api.github.com/repos/postmates/pycernan/issues/31/comments","statuses_url":"https://api.github.com/repos/postmates/pycernan/statuses/d320ab6b8aea62b325bdf8f574cf9a526ec9ba2f","head":{"label":"postmates:add-connection-pooling","ref":"add-connection-pooling","sha":"d320ab6b8aea62b325bdf8f574cf9a526ec9ba2f","user":{"login":"postmates","id":426014,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyNjAxNA==","avatar_url":"https://avatars1.githubusercontent.com/u/426014?v=4","gravatar_id":"","url":"https://api.github.com/users/postmates","html_url":"https://github.com/postmates","followers_url":"https://api.github.com/users/postmates/followers","following_url":"https://api.github.com/users/postmates/following{/other_user}","gists_url":"https://api.github.com/users/postmates/gists{/gist_id}","starred_url":"https://api.github.com/users/postmates/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/postmates/subscriptions","organizations_url":"https://api.github.com/users/postmates/orgs","repos_url":"https://api.github.com/users/postmates/repos","events_url":"https://api.github.com/users/postmates/events{/privacy}","received_events_url":"https://api.github.com/users/postmates/received_events","type":"Organization","site_admin":false},"repo":{"id":116191657,"node_id":"MDEwOlJlcG9zaXRvcnkxMTYxOTE2NTc=","name":"pycernan","full_name":"postmates/pycernan","private":false,"owner":{"login":"postmates","id":426014,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyNjAxNA==","avatar_url":"https://avatars1.githubusercontent.com/u/426014?v=4","gravatar_id":"","url":"https://api.github.com/users/postmates","html_url":"https://github.com/postmates","followers_url":"https://api.github.com/users/postmates/followers","following_url":"https://api.github.com/users/postmates/following{/other_user}","gists_url":"https://api.github.com/users/postmates/gists{/gist_id}","starred_url":"https://api.github.com/users/postmates/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/postmates/subscriptions","organizations_url":"https://api.github.com/users/postmates/orgs","repos_url":"https://api.github.com/users/postmates/repos","events_url":"https://api.github.com/users/postmates/events{/privacy}","received_events_url":"https://api.github.com/users/postmates/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/postmates/pycernan","description":"A Python Client for Cernan","fork":false,"url":"https://api.github.com/repos/postmates/pycernan","forks_url":"https://api.github.com/repos/postmates/pycernan/forks","keys_url":"https://api.github.com/repos/postmates/pycernan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/postmates/pycernan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/postmates/pycernan/teams","hooks_url":"https://api.github.com/repos/postmates/pycernan/hooks","issue_events_url":"https://api.github.com/repos/postmates/pycernan/issues/events{/number}","events_url":"https://api.github.com/repos/postmates/pycernan/events","assignees_url":"https://api.github.com/repos/postmates/pycernan/assignees{/user}","branches_url":"https://api.github.com/repos/postmates/pycernan/branches{/branch}","tags_url":"https://api.github.com/repos/postmates/pycernan/tags","blobs_url":"https://api.github.com/repos/postmates/pycernan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/postmates/pycernan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/postmates/pycernan/git/refs{/sha}","trees_url":"https://api.github.com/repos/postmates/pycernan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/postmates/pycernan/statuses/{sha}","languages_url":"https://api.github.com/repos/postmates/pycernan/languages","stargazers_url":"https://api.github.com/repos/postmates/pycernan/stargazers","contributors_url":"https://api.github.com/repos/postmates/pycernan/contributors","subscribers_url":"https://api.github.com/repos/postmates/pycernan/subscribers","subscription_url":"https://api.github.com/repos/postmates/pycernan/subscription","commits_url":"https://api.github.com/repos/postmates/pycernan/commits{/sha}","git_commits_url":"https://api.github.com/repos/postmates/pycernan/git/commits{/sha}","comments_url":"https://api.github.com/repos/postmates/pycernan/comments{/number}","issue_comment_url":"https://api.github.com/repos/postmates/pycernan/issues/comments{/number}","contents_url":"https://api.github.com/repos/postmates/pycernan/contents/{+path}","compare_url":"https://api.github.com/repos/postmates/pycernan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/postmates/pycernan/merges","archive_url":"https://api.github.com/repos/postmates/pycernan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/postmates/pycernan/downloads","issues_url":"https://api.github.com/repos/postmates/pycernan/issues{/number}","pulls_url":"https://api.github.com/repos/postmates/pycernan/pulls{/number}","milestones_url":"https://api.github.com/repos/postmates/pycernan/milestones{/number}","notifications_url":"https://api.github.com/repos/postmates/pycernan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/postmates/pycernan/labels{/name}","releases_url":"https://api.github.com/repos/postmates/pycernan/releases{/id}","deployments_url":"https://api.github.com/repos/postmates/pycernan/deployments","created_at":"2018-01-03T23:20:28Z","updated_at":"2018-07-09T21:25:51Z","pushed_at":"2018-11-15T15:26:46Z","git_url":"git://github.com/postmates/pycernan.git","ssh_url":"git@github.com:postmates/pycernan.git","clone_url":"https://github.com/postmates/pycernan.git","svn_url":"https://github.com/postmates/pycernan","homepage":null,"size":1013,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"postmates:master","ref":"master","sha":"ed91ed578c9bae6958a4181bb1d0ae0b3c5550ce","user":{"login":"postmates","id":426014,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyNjAxNA==","avatar_url":"https://avatars1.githubusercontent.com/u/426014?v=4","gravatar_id":"","url":"https://api.github.com/users/postmates","html_url":"https://github.com/postmates","followers_url":"https://api.github.com/users/postmates/followers","following_url":"https://api.github.com/users/postmates/following{/other_user}","gists_url":"https://api.github.com/users/postmates/gists{/gist_id}","starred_url":"https://api.github.com/users/postmates/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/postmates/subscriptions","organizations_url":"https://api.github.com/users/postmates/orgs","repos_url":"https://api.github.com/users/postmates/repos","events_url":"https://api.github.com/users/postmates/events{/privacy}","received_events_url":"https://api.github.com/users/postmates/received_events","type":"Organization","site_admin":false},"repo":{"id":116191657,"node_id":"MDEwOlJlcG9zaXRvcnkxMTYxOTE2NTc=","name":"pycernan","full_name":"postmates/pycernan","private":false,"owner":{"login":"postmates","id":426014,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyNjAxNA==","avatar_url":"https://avatars1.githubusercontent.com/u/426014?v=4","gravatar_id":"","url":"https://api.github.com/users/postmates","html_url":"https://github.com/postmates","followers_url":"https://api.github.com/users/postmates/followers","following_url":"https://api.github.com/users/postmates/following{/other_user}","gists_url":"https://api.github.com/users/postmates/gists{/gist_id}","starred_url":"https://api.github.com/users/postmates/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/postmates/subscriptions","organizations_url":"https://api.github.com/users/postmates/orgs","repos_url":"https://api.github.com/users/postmates/repos","events_url":"https://api.github.com/users/postmates/events{/privacy}","received_events_url":"https://api.github.com/users/postmates/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/postmates/pycernan","description":"A Python Client for Cernan","fork":false,"url":"https://api.github.com/repos/postmates/pycernan","forks_url":"https://api.github.com/repos/postmates/pycernan/forks","keys_url":"https://api.github.com/repos/postmates/pycernan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/postmates/pycernan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/postmates/pycernan/teams","hooks_url":"https://api.github.com/repos/postmates/pycernan/hooks","issue_events_url":"https://api.github.com/repos/postmates/pycernan/issues/events{/number}","events_url":"https://api.github.com/repos/postmates/pycernan/events","assignees_url":"https://api.github.com/repos/postmates/pycernan/assignees{/user}","branches_url":"https://api.github.com/repos/postmates/pycernan/branches{/branch}","tags_url":"https://api.github.com/repos/postmates/pycernan/tags","blobs_url":"https://api.github.com/repos/postmates/pycernan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/postmates/pycernan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/postmates/pycernan/git/refs{/sha}","trees_url":"https://api.github.com/repos/postmates/pycernan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/postmates/pycernan/statuses/{sha}","languages_url":"https://api.github.com/repos/postmates/pycernan/languages","stargazers_url":"https://api.github.com/repos/postmates/pycernan/stargazers","contributors_url":"https://api.github.com/repos/postmates/pycernan/contributors","subscribers_url":"https://api.github.com/repos/postmates/pycernan/subscribers","subscription_url":"https://api.github.com/repos/postmates/pycernan/subscription","commits_url":"https://api.github.com/repos/postmates/pycernan/commits{/sha}","git_commits_url":"https://api.github.com/repos/postmates/pycernan/git/commits{/sha}","comments_url":"https://api.github.com/repos/postmates/pycernan/comments{/number}","issue_comment_url":"https://api.github.com/repos/postmates/pycernan/issues/comments{/number}","contents_url":"https://api.github.com/repos/postmates/pycernan/contents/{+path}","compare_url":"https://api.github.com/repos/postmates/pycernan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/postmates/pycernan/merges","archive_url":"https://api.github.com/repos/postmates/pycernan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/postmates/pycernan/downloads","issues_url":"https://api.github.com/repos/postmates/pycernan/issues{/number}","pulls_url":"https://api.github.com/repos/postmates/pycernan/pulls{/number}","milestones_url":"https://api.github.com/repos/postmates/pycernan/milestones{/number}","notifications_url":"https://api.github.com/repos/postmates/pycernan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/postmates/pycernan/labels{/name}","releases_url":"https://api.github.com/repos/postmates/pycernan/releases{/id}","deployments_url":"https://api.github.com/repos/postmates/pycernan/deployments","created_at":"2018-01-03T23:20:28Z","updated_at":"2018-07-09T21:25:51Z","pushed_at":"2018-11-15T15:26:46Z","git_url":"git://github.com/postmates/pycernan.git","ssh_url":"git@github.com:postmates/pycernan.git","clone_url":"https://github.com/postmates/pycernan.git","svn_url":"https://github.com/postmates/pycernan","homepage":null,"size":1013,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/postmates/pycernan/pulls/31"},"html":{"href":"https://github.com/postmates/pycernan/pull/31"},"issue":{"href":"https://api.github.com/repos/postmates/pycernan/issues/31"},"comments":{"href":"https://api.github.com/repos/postmates/pycernan/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/postmates/pycernan/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/postmates/pycernan/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/postmates/pycernan/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/postmates/pycernan/statuses/d320ab6b8aea62b325bdf8f574cf9a526ec9ba2f"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"pulltab"}}