{"action":"created","comment":{"url":"https://api.github.com/repos/genome/nessy-client-perl/pulls/comments/24937101","id":24937101,"diff_hunk":"@@ -26,47 +26,76 @@ my $MESSAGE_SERIAL = 1;\n sub new {\n     my($class, %params) = @_;\n \n-    my $api_version = $params{api_version} || $class->_default_api_version;\n+    $class->_verify_constructor_params(\\%params);\n \n-    my $url = $params{url} || Carp::croak('url is a required param');\n-\n-    my($socket1, $socket2) = IO::Socket->socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC);\n-\n-    $_->autoflush(1) foreach ($socket1, $socket2);\n-\n-    my $pid = _fork();\n+    my $pid = $class->_fork();\n     if ($pid) {\n         my $self = bless {}, $class;\n-        $self->api_version($api_version);\n         $self->pid($pid);\n-        $self->default_ttl( $params{default_ttl} || $class->_default_ttl );\n-        $self->default_timeout( $params{default_timeout} || $class->_default_timeout );\n-        $self->serial_responder_registry({});\n-\n-        my $watcher = $self->_create_socket_watcher($socket1);\n-        $self->socket_watcher($watcher);\n-\n-        $socket2->close();\n-\n+        $self->_parent_process_setup(%params);\n         return $self;\n \n     } elsif (defined $pid) {\n-        eval {\n-            $socket1->close();\n-            my $daemon_class = $class->_daemon_class_name;\n-            my $daemon = $daemon_class->new(\n-                                url => $url,\n-                                client_socket => $socket2,\n-                                api_version => $api_version);\n-            $daemon->run();\n-        };\n-        Carp::croak($@) if $@;\n+        $class->_run_child_process(%params);\n         exit;\n     } else {\n         Carp::croak(\"Can't fork: $!\");\n     }\n }\n \n+sub _verify_constructor_params {\n+    my($class, $params) = @_;\n+\n+    $params->{api_version} ||= $class->_default_api_version;\n+    $params->{url} || Carp::croak('url is a required param');\n+    $params->{'socketpair'} ||= [ $class->_make_socket_pair_for_daemon_comms() ];\n+\n+    return $params;\n+}\n+\n+sub _make_socket_pair_for_daemon_comms {\n+    my($socket1, $socket2) = IO::Socket->socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC);\n+    $_->autoflush(1) foreach ($socket1, $socket2);","path":"lib/Nessy/Client.pm","position":61,"original_position":61,"commit_id":"10f702c7fb8a0c524d8f57e1c261a9839025521e","original_commit_id":"10f702c7fb8a0c524d8f57e1c261a9839025521e","user":{"login":"brummett","id":111808,"avatar_url":"https://avatars.githubusercontent.com/u/111808?v=3","gravatar_id":"","url":"https://api.github.com/users/brummett","html_url":"https://github.com/brummett","followers_url":"https://api.github.com/users/brummett/followers","following_url":"https://api.github.com/users/brummett/following{/other_user}","gists_url":"https://api.github.com/users/brummett/gists{/gist_id}","starred_url":"https://api.github.com/users/brummett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brummett/subscriptions","organizations_url":"https://api.github.com/users/brummett/orgs","repos_url":"https://api.github.com/users/brummett/repos","events_url":"https://api.github.com/users/brummett/events{/privacy}","received_events_url":"https://api.github.com/users/brummett/received_events","type":"User","site_admin":false},"body":"While that looks cleaner, the ```autoflush()``` method returns the previous autoflush value, not the handle, so map won't work here.  It would have to be slightly more messy:\r\n```\r\nmy($socket1, $socket2) = map { $_->autoflush(1); $_ }\r\n                                          IO::Socket->sockpair(...);\r\n```\r\n","created_at":"2015-02-18T20:24:28Z","updated_at":"2015-02-18T20:24:28Z","html_url":"https://github.com/genome/nessy-client-perl/pull/41#discussion_r24937101","pull_request_url":"https://api.github.com/repos/genome/nessy-client-perl/pulls/41","_links":{"self":{"href":"https://api.github.com/repos/genome/nessy-client-perl/pulls/comments/24937101"},"html":{"href":"https://github.com/genome/nessy-client-perl/pull/41#discussion_r24937101"},"pull_request":{"href":"https://api.github.com/repos/genome/nessy-client-perl/pulls/41"}}},"pull_request":{"url":"https://api.github.com/repos/genome/nessy-client-perl/pulls/41","id":29223292,"html_url":"https://github.com/genome/nessy-client-perl/pull/41","diff_url":"https://github.com/genome/nessy-client-perl/pull/41.diff","patch_url":"https://github.com/genome/nessy-client-perl/pull/41.patch","issue_url":"https://api.github.com/repos/genome/nessy-client-perl/issues/41","number":41,"state":"open","locked":false,"title":"Don't block when the daemon dies","user":{"login":"brummett","id":111808,"avatar_url":"https://avatars.githubusercontent.com/u/111808?v=3","gravatar_id":"","url":"https://api.github.com/users/brummett","html_url":"https://github.com/brummett","followers_url":"https://api.github.com/users/brummett/followers","following_url":"https://api.github.com/users/brummett/following{/other_user}","gists_url":"https://api.github.com/users/brummett/gists{/gist_id}","starred_url":"https://api.github.com/users/brummett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brummett/subscriptions","organizations_url":"https://api.github.com/users/brummett/orgs","repos_url":"https://api.github.com/users/brummett/repos","events_url":"https://api.github.com/users/brummett/events{/privacy}","received_events_url":"https://api.github.com/users/brummett/received_events","type":"User","site_admin":false},"body":"If the daemon went away, the client would get notified of the EOF, but wouldn't relay that info to whatever was waiting on a response.\r\n\r\nThis changes it so any outstanding requests get notified of failure if the socket to the daemon closes.\r\n\r\nThe first several commits is just refactoring to make a test case easier to write.  The last 2 fix the problem.","created_at":"2015-02-12T22:35:08Z","updated_at":"2015-02-18T20:24:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"08a8f4b83086dcaae01dcda5b61d31732b57dcbd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/genome/nessy-client-perl/pulls/41/commits","review_comments_url":"https://api.github.com/repos/genome/nessy-client-perl/pulls/41/comments","review_comment_url":"https://api.github.com/repos/genome/nessy-client-perl/pulls/comments/{number}","comments_url":"https://api.github.com/repos/genome/nessy-client-perl/issues/41/comments","statuses_url":"https://api.github.com/repos/genome/nessy-client-perl/statuses/10f702c7fb8a0c524d8f57e1c261a9839025521e","head":{"label":"brummett:eof","ref":"eof","sha":"10f702c7fb8a0c524d8f57e1c261a9839025521e","user":{"login":"brummett","id":111808,"avatar_url":"https://avatars.githubusercontent.com/u/111808?v=3","gravatar_id":"","url":"https://api.github.com/users/brummett","html_url":"https://github.com/brummett","followers_url":"https://api.github.com/users/brummett/followers","following_url":"https://api.github.com/users/brummett/following{/other_user}","gists_url":"https://api.github.com/users/brummett/gists{/gist_id}","starred_url":"https://api.github.com/users/brummett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brummett/subscriptions","organizations_url":"https://api.github.com/users/brummett/orgs","repos_url":"https://api.github.com/users/brummett/repos","events_url":"https://api.github.com/users/brummett/events{/privacy}","received_events_url":"https://api.github.com/users/brummett/received_events","type":"User","site_admin":false},"repo":{"id":18407143,"name":"nessy-client-perl","full_name":"brummett/nessy-client-perl","owner":{"login":"brummett","id":111808,"avatar_url":"https://avatars.githubusercontent.com/u/111808?v=3","gravatar_id":"","url":"https://api.github.com/users/brummett","html_url":"https://github.com/brummett","followers_url":"https://api.github.com/users/brummett/followers","following_url":"https://api.github.com/users/brummett/following{/other_user}","gists_url":"https://api.github.com/users/brummett/gists{/gist_id}","starred_url":"https://api.github.com/users/brummett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brummett/subscriptions","organizations_url":"https://api.github.com/users/brummett/orgs","repos_url":"https://api.github.com/users/brummett/repos","events_url":"https://api.github.com/users/brummett/events{/privacy}","received_events_url":"https://api.github.com/users/brummett/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brummett/nessy-client-perl","description":"Perl client for the nessy-server lock daemon","fork":true,"url":"https://api.github.com/repos/brummett/nessy-client-perl","forks_url":"https://api.github.com/repos/brummett/nessy-client-perl/forks","keys_url":"https://api.github.com/repos/brummett/nessy-client-perl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brummett/nessy-client-perl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brummett/nessy-client-perl/teams","hooks_url":"https://api.github.com/repos/brummett/nessy-client-perl/hooks","issue_events_url":"https://api.github.com/repos/brummett/nessy-client-perl/issues/events{/number}","events_url":"https://api.github.com/repos/brummett/nessy-client-perl/events","assignees_url":"https://api.github.com/repos/brummett/nessy-client-perl/assignees{/user}","branches_url":"https://api.github.com/repos/brummett/nessy-client-perl/branches{/branch}","tags_url":"https://api.github.com/repos/brummett/nessy-client-perl/tags","blobs_url":"https://api.github.com/repos/brummett/nessy-client-perl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brummett/nessy-client-perl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brummett/nessy-client-perl/git/refs{/sha}","trees_url":"https://api.github.com/repos/brummett/nessy-client-perl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brummett/nessy-client-perl/statuses/{sha}","languages_url":"https://api.github.com/repos/brummett/nessy-client-perl/languages","stargazers_url":"https://api.github.com/repos/brummett/nessy-client-perl/stargazers","contributors_url":"https://api.github.com/repos/brummett/nessy-client-perl/contributors","subscribers_url":"https://api.github.com/repos/brummett/nessy-client-perl/subscribers","subscription_url":"https://api.github.com/repos/brummett/nessy-client-perl/subscription","commits_url":"https://api.github.com/repos/brummett/nessy-client-perl/commits{/sha}","git_commits_url":"https://api.github.com/repos/brummett/nessy-client-perl/git/commits{/sha}","comments_url":"https://api.github.com/repos/brummett/nessy-client-perl/comments{/number}","issue_comment_url":"https://api.github.com/repos/brummett/nessy-client-perl/issues/comments/{number}","contents_url":"https://api.github.com/repos/brummett/nessy-client-perl/contents/{+path}","compare_url":"https://api.github.com/repos/brummett/nessy-client-perl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brummett/nessy-client-perl/merges","archive_url":"https://api.github.com/repos/brummett/nessy-client-perl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brummett/nessy-client-perl/downloads","issues_url":"https://api.github.com/repos/brummett/nessy-client-perl/issues{/number}","pulls_url":"https://api.github.com/repos/brummett/nessy-client-perl/pulls{/number}","milestones_url":"https://api.github.com/repos/brummett/nessy-client-perl/milestones{/number}","notifications_url":"https://api.github.com/repos/brummett/nessy-client-perl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brummett/nessy-client-perl/labels{/name}","releases_url":"https://api.github.com/repos/brummett/nessy-client-perl/releases{/id}","created_at":"2014-04-03T15:02:28Z","updated_at":"2014-10-07T22:49:38Z","pushed_at":"2015-02-12T22:32:21Z","git_url":"git://github.com/brummett/nessy-client-perl.git","ssh_url":"git@github.com:brummett/nessy-client-perl.git","clone_url":"https://github.com/brummett/nessy-client-perl.git","svn_url":"https://github.com/brummett/nessy-client-perl","homepage":"","size":496,"stargazers_count":0,"watchers_count":0,"language":"Perl","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":"genome:master","ref":"master","sha":"eeadf23f9f8bf24cca9c9f6b45f5472ac71e6e5e","user":{"login":"genome","id":318108,"avatar_url":"https://avatars.githubusercontent.com/u/318108?v=3","gravatar_id":"","url":"https://api.github.com/users/genome","html_url":"https://github.com/genome","followers_url":"https://api.github.com/users/genome/followers","following_url":"https://api.github.com/users/genome/following{/other_user}","gists_url":"https://api.github.com/users/genome/gists{/gist_id}","starred_url":"https://api.github.com/users/genome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genome/subscriptions","organizations_url":"https://api.github.com/users/genome/orgs","repos_url":"https://api.github.com/users/genome/repos","events_url":"https://api.github.com/users/genome/events{/privacy}","received_events_url":"https://api.github.com/users/genome/received_events","type":"Organization","site_admin":false},"repo":{"id":16422650,"name":"nessy-client-perl","full_name":"genome/nessy-client-perl","owner":{"login":"genome","id":318108,"avatar_url":"https://avatars.githubusercontent.com/u/318108?v=3","gravatar_id":"","url":"https://api.github.com/users/genome","html_url":"https://github.com/genome","followers_url":"https://api.github.com/users/genome/followers","following_url":"https://api.github.com/users/genome/following{/other_user}","gists_url":"https://api.github.com/users/genome/gists{/gist_id}","starred_url":"https://api.github.com/users/genome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genome/subscriptions","organizations_url":"https://api.github.com/users/genome/orgs","repos_url":"https://api.github.com/users/genome/repos","events_url":"https://api.github.com/users/genome/events{/privacy}","received_events_url":"https://api.github.com/users/genome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/genome/nessy-client-perl","description":"Perl client for the nessy-server lock daemon","fork":false,"url":"https://api.github.com/repos/genome/nessy-client-perl","forks_url":"https://api.github.com/repos/genome/nessy-client-perl/forks","keys_url":"https://api.github.com/repos/genome/nessy-client-perl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/genome/nessy-client-perl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/genome/nessy-client-perl/teams","hooks_url":"https://api.github.com/repos/genome/nessy-client-perl/hooks","issue_events_url":"https://api.github.com/repos/genome/nessy-client-perl/issues/events{/number}","events_url":"https://api.github.com/repos/genome/nessy-client-perl/events","assignees_url":"https://api.github.com/repos/genome/nessy-client-perl/assignees{/user}","branches_url":"https://api.github.com/repos/genome/nessy-client-perl/branches{/branch}","tags_url":"https://api.github.com/repos/genome/nessy-client-perl/tags","blobs_url":"https://api.github.com/repos/genome/nessy-client-perl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/genome/nessy-client-perl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/genome/nessy-client-perl/git/refs{/sha}","trees_url":"https://api.github.com/repos/genome/nessy-client-perl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/genome/nessy-client-perl/statuses/{sha}","languages_url":"https://api.github.com/repos/genome/nessy-client-perl/languages","stargazers_url":"https://api.github.com/repos/genome/nessy-client-perl/stargazers","contributors_url":"https://api.github.com/repos/genome/nessy-client-perl/contributors","subscribers_url":"https://api.github.com/repos/genome/nessy-client-perl/subscribers","subscription_url":"https://api.github.com/repos/genome/nessy-client-perl/subscription","commits_url":"https://api.github.com/repos/genome/nessy-client-perl/commits{/sha}","git_commits_url":"https://api.github.com/repos/genome/nessy-client-perl/git/commits{/sha}","comments_url":"https://api.github.com/repos/genome/nessy-client-perl/comments{/number}","issue_comment_url":"https://api.github.com/repos/genome/nessy-client-perl/issues/comments/{number}","contents_url":"https://api.github.com/repos/genome/nessy-client-perl/contents/{+path}","compare_url":"https://api.github.com/repos/genome/nessy-client-perl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/genome/nessy-client-perl/merges","archive_url":"https://api.github.com/repos/genome/nessy-client-perl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/genome/nessy-client-perl/downloads","issues_url":"https://api.github.com/repos/genome/nessy-client-perl/issues{/number}","pulls_url":"https://api.github.com/repos/genome/nessy-client-perl/pulls{/number}","milestones_url":"https://api.github.com/repos/genome/nessy-client-perl/milestones{/number}","notifications_url":"https://api.github.com/repos/genome/nessy-client-perl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/genome/nessy-client-perl/labels{/name}","releases_url":"https://api.github.com/repos/genome/nessy-client-perl/releases{/id}","created_at":"2014-01-31T22:28:10Z","updated_at":"2014-12-30T15:05:49Z","pushed_at":"2014-12-30T15:05:49Z","git_url":"git://github.com/genome/nessy-client-perl.git","ssh_url":"git@github.com:genome/nessy-client-perl.git","clone_url":"https://github.com/genome/nessy-client-perl.git","svn_url":"https://github.com/genome/nessy-client-perl","homepage":"","size":826,"stargazers_count":1,"watchers_count":1,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":2,"forks":4,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/genome/nessy-client-perl/pulls/41"},"html":{"href":"https://github.com/genome/nessy-client-perl/pull/41"},"issue":{"href":"https://api.github.com/repos/genome/nessy-client-perl/issues/41"},"comments":{"href":"https://api.github.com/repos/genome/nessy-client-perl/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/genome/nessy-client-perl/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/genome/nessy-client-perl/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/genome/nessy-client-perl/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/genome/nessy-client-perl/statuses/10f702c7fb8a0c524d8f57e1c261a9839025521e"}}}}