{"action":"created","comment":{"url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/comments/25406252","id":25406252,"diff_hunk":"@@ -121,45 +119,38 @@ sparkR.init <- function(\n   if (sparkRExistingPort != \"\") {\n     sparkRBackendPort <- sparkRExistingPort\n   } else {\n+    # TODO: test the random port and retry, or use httpuv:::startServer\n+    callbackPort = sample(40000, 1) + 10000\n     if (Sys.getenv(\"SPARKR_USE_SPARK_SUBMIT\", \"\") == \"\") {\n       launchBackend(classPath = cp,\n                     mainClass = \"edu.berkeley.cs.amplab.sparkr.SparkRBackend\",\n-                    args = as.character(sparkRBackendPort),\n+                    args = as.character(callbackPort),\n                     javaOpts = paste(\"-Xmx\", sparkMem, sep = \"\"))\n     } else {\n       # TODO: We should deprecate sparkJars and ask users to add it to the\n       # command line (using --jars) which is picked up by SparkSubmit\n       launchBackendSparkSubmit(\n           mainClass = \"edu.berkeley.cs.amplab.sparkr.SparkRBackend\",\n-          args = as.character(sparkRBackendPort),\n+          args = as.character(callbackPort),\n           appJar = .sparkREnv$assemblyJarPath,\n           sparkHome = sparkHome,\n           sparkSubmitOpts = Sys.getenv(\"SPARKR_SUBMIT_ARGS\", \"\"))\n     }\n+    sock <- socketConnection(port = callbackPort, server = TRUE, open = 'rb',","path":"pkg/R/sparkR.R","position":34,"original_position":34,"commit_id":"4e712e18682d5fa80039867b4a66e52d332556d2","original_commit_id":"4e712e18682d5fa80039867b4a66e52d332556d2","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"body":"This problem is that this line will block until a client connection come up, so we can not move it before launch JVM (it's weird that R does not have a fully functional socket library).\r\n\r\nThere is a race condition here, but given the fact that JVM usually take 1-2 seconds to startup, the risk is very low. We can see it actual cause problem or not.","created_at":"2015-02-26T05:53:16Z","updated_at":"2015-02-26T05:53:16Z","html_url":"https://github.com/amplab-extras/SparkR-pkg/pull/178#discussion_r25406252","pull_request_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/178","_links":{"self":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/comments/25406252"},"html":{"href":"https://github.com/amplab-extras/SparkR-pkg/pull/178#discussion_r25406252"},"pull_request":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/178"}}},"pull_request":{"url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/178","id":29968991,"html_url":"https://github.com/amplab-extras/SparkR-pkg/pull/178","diff_url":"https://github.com/amplab-extras/SparkR-pkg/pull/178.diff","patch_url":"https://github.com/amplab-extras/SparkR-pkg/pull/178.patch","issue_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/178","number":178,"state":"open","locked":false,"title":"[SPARKR-204] use random port in backend","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"body":"Backend will bind to random port, and send back to R via another socket.","created_at":"2015-02-25T08:37:22Z","updated_at":"2015-02-26T05:53:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3989327c07b76d12339ee3a64146313854d81588","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/178/commits","review_comments_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/178/comments","review_comment_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/178/comments","statuses_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/statuses/4e712e18682d5fa80039867b4a66e52d332556d2","head":{"label":"davies:random","ref":"random","sha":"4e712e18682d5fa80039867b4a66e52d332556d2","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"repo":{"id":31027661,"name":"SparkR-pkg","full_name":"davies/SparkR-pkg","owner":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davies/SparkR-pkg","description":"R frontend for Spark","fork":true,"url":"https://api.github.com/repos/davies/SparkR-pkg","forks_url":"https://api.github.com/repos/davies/SparkR-pkg/forks","keys_url":"https://api.github.com/repos/davies/SparkR-pkg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davies/SparkR-pkg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davies/SparkR-pkg/teams","hooks_url":"https://api.github.com/repos/davies/SparkR-pkg/hooks","issue_events_url":"https://api.github.com/repos/davies/SparkR-pkg/issues/events{/number}","events_url":"https://api.github.com/repos/davies/SparkR-pkg/events","assignees_url":"https://api.github.com/repos/davies/SparkR-pkg/assignees{/user}","branches_url":"https://api.github.com/repos/davies/SparkR-pkg/branches{/branch}","tags_url":"https://api.github.com/repos/davies/SparkR-pkg/tags","blobs_url":"https://api.github.com/repos/davies/SparkR-pkg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davies/SparkR-pkg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davies/SparkR-pkg/git/refs{/sha}","trees_url":"https://api.github.com/repos/davies/SparkR-pkg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davies/SparkR-pkg/statuses/{sha}","languages_url":"https://api.github.com/repos/davies/SparkR-pkg/languages","stargazers_url":"https://api.github.com/repos/davies/SparkR-pkg/stargazers","contributors_url":"https://api.github.com/repos/davies/SparkR-pkg/contributors","subscribers_url":"https://api.github.com/repos/davies/SparkR-pkg/subscribers","subscription_url":"https://api.github.com/repos/davies/SparkR-pkg/subscription","commits_url":"https://api.github.com/repos/davies/SparkR-pkg/commits{/sha}","git_commits_url":"https://api.github.com/repos/davies/SparkR-pkg/git/commits{/sha}","comments_url":"https://api.github.com/repos/davies/SparkR-pkg/comments{/number}","issue_comment_url":"https://api.github.com/repos/davies/SparkR-pkg/issues/comments{/number}","contents_url":"https://api.github.com/repos/davies/SparkR-pkg/contents/{+path}","compare_url":"https://api.github.com/repos/davies/SparkR-pkg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davies/SparkR-pkg/merges","archive_url":"https://api.github.com/repos/davies/SparkR-pkg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davies/SparkR-pkg/downloads","issues_url":"https://api.github.com/repos/davies/SparkR-pkg/issues{/number}","pulls_url":"https://api.github.com/repos/davies/SparkR-pkg/pulls{/number}","milestones_url":"https://api.github.com/repos/davies/SparkR-pkg/milestones{/number}","notifications_url":"https://api.github.com/repos/davies/SparkR-pkg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davies/SparkR-pkg/labels{/name}","releases_url":"https://api.github.com/repos/davies/SparkR-pkg/releases{/id}","created_at":"2015-02-19T17:37:52Z","updated_at":"2015-02-25T08:33:46Z","pushed_at":"2015-02-25T22:52:34Z","git_url":"git://github.com/davies/SparkR-pkg.git","ssh_url":"git@github.com:davies/SparkR-pkg.git","clone_url":"https://github.com/davies/SparkR-pkg.git","svn_url":"https://github.com/davies/SparkR-pkg","homepage":"http://amplab-extras.github.io/SparkR-pkg","size":3372,"stargazers_count":0,"watchers_count":0,"language":"R","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"amplab-extras:master","ref":"master","sha":"c10148e07525e7d3b5c5b2be1b2b8c45a6c495fd","user":{"login":"amplab-extras","id":6403540,"avatar_url":"https://avatars.githubusercontent.com/u/6403540?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab-extras","html_url":"https://github.com/amplab-extras","followers_url":"https://api.github.com/users/amplab-extras/followers","following_url":"https://api.github.com/users/amplab-extras/following{/other_user}","gists_url":"https://api.github.com/users/amplab-extras/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab-extras/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab-extras/subscriptions","organizations_url":"https://api.github.com/users/amplab-extras/orgs","repos_url":"https://api.github.com/users/amplab-extras/repos","events_url":"https://api.github.com/users/amplab-extras/events{/privacy}","received_events_url":"https://api.github.com/users/amplab-extras/received_events","type":"Organization","site_admin":false},"repo":{"id":15365789,"name":"SparkR-pkg","full_name":"amplab-extras/SparkR-pkg","owner":{"login":"amplab-extras","id":6403540,"avatar_url":"https://avatars.githubusercontent.com/u/6403540?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab-extras","html_url":"https://github.com/amplab-extras","followers_url":"https://api.github.com/users/amplab-extras/followers","following_url":"https://api.github.com/users/amplab-extras/following{/other_user}","gists_url":"https://api.github.com/users/amplab-extras/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab-extras/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab-extras/subscriptions","organizations_url":"https://api.github.com/users/amplab-extras/orgs","repos_url":"https://api.github.com/users/amplab-extras/repos","events_url":"https://api.github.com/users/amplab-extras/events{/privacy}","received_events_url":"https://api.github.com/users/amplab-extras/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/amplab-extras/SparkR-pkg","description":"R frontend for Spark","fork":false,"url":"https://api.github.com/repos/amplab-extras/SparkR-pkg","forks_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/forks","keys_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/teams","hooks_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/hooks","issue_events_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/events{/number}","events_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/events","assignees_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/assignees{/user}","branches_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/branches{/branch}","tags_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/tags","blobs_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/refs{/sha}","trees_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/statuses/{sha}","languages_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/languages","stargazers_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/stargazers","contributors_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/contributors","subscribers_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/subscribers","subscription_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/subscription","commits_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/commits{/sha}","git_commits_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/commits{/sha}","comments_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/comments{/number}","issue_comment_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/comments{/number}","contents_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/contents/{+path}","compare_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/merges","archive_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/downloads","issues_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues{/number}","pulls_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls{/number}","milestones_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/milestones{/number}","notifications_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/labels{/name}","releases_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/releases{/id}","created_at":"2013-12-21T21:16:54Z","updated_at":"2015-02-25T18:35:22Z","pushed_at":"2015-02-25T06:33:22Z","git_url":"git://github.com/amplab-extras/SparkR-pkg.git","ssh_url":"git@github.com:amplab-extras/SparkR-pkg.git","clone_url":"https://github.com/amplab-extras/SparkR-pkg.git","svn_url":"https://github.com/amplab-extras/SparkR-pkg","homepage":"http://amplab-extras.github.io/SparkR-pkg","size":5360,"stargazers_count":400,"watchers_count":400,"language":"R","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":141,"mirror_url":null,"open_issues_count":26,"forks":141,"open_issues":26,"watchers":400,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/178"},"html":{"href":"https://github.com/amplab-extras/SparkR-pkg/pull/178"},"issue":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/178"},"comments":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/178/comments"},"review_comments":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/178/comments"},"review_comment":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/178/commits"},"statuses":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/statuses/4e712e18682d5fa80039867b4a66e52d332556d2"}}}}