{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/12598","labels_url":"https://api.github.com/repos/golang/go/issues/12598/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/12598/comments","events_url":"https://api.github.com/repos/golang/go/issues/12598/events","html_url":"https://github.com/golang/go/issues/12598","id":106141231,"number":12598,"title":"x/mobile Android net.Dial(\"tcp\", ip, port) returns \"protocol not available\"","user":{"login":"diegomontoya","id":417764,"avatar_url":"https://avatars.githubusercontent.com/u/417764?v=3","gravatar_id":"","url":"https://api.github.com/users/diegomontoya","html_url":"https://github.com/diegomontoya","followers_url":"https://api.github.com/users/diegomontoya/followers","following_url":"https://api.github.com/users/diegomontoya/following{/other_user}","gists_url":"https://api.github.com/users/diegomontoya/gists{/gist_id}","starred_url":"https://api.github.com/users/diegomontoya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diegomontoya/subscriptions","organizations_url":"https://api.github.com/users/diegomontoya/orgs","repos_url":"https://api.github.com/users/diegomontoya/repos","events_url":"https://api.github.com/users/diegomontoya/events{/privacy}","received_events_url":"https://api.github.com/users/diegomontoya/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"mikioh","id":92117,"avatar_url":"https://avatars.githubusercontent.com/u/92117?v=3","gravatar_id":"","url":"https://api.github.com/users/mikioh","html_url":"https://github.com/mikioh","followers_url":"https://api.github.com/users/mikioh/followers","following_url":"https://api.github.com/users/mikioh/following{/other_user}","gists_url":"https://api.github.com/users/mikioh/gists{/gist_id}","starred_url":"https://api.github.com/users/mikioh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikioh/subscriptions","organizations_url":"https://api.github.com/users/mikioh/orgs","repos_url":"https://api.github.com/users/mikioh/repos","events_url":"https://api.github.com/users/mikioh/events{/privacy}","received_events_url":"https://api.github.com/users/mikioh/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/24","html_url":"https://github.com/golang/go/milestones/Go1.6","labels_url":"https://api.github.com/repos/golang/go/milestones/24/labels","id":1096159,"number":24,"title":"Go1.6","description":"","creator":{"login":"josharian","id":67496,"avatar_url":"https://avatars.githubusercontent.com/u/67496?v=3","gravatar_id":"","url":"https://api.github.com/users/josharian","html_url":"https://github.com/josharian","followers_url":"https://api.github.com/users/josharian/followers","following_url":"https://api.github.com/users/josharian/following{/other_user}","gists_url":"https://api.github.com/users/josharian/gists{/gist_id}","starred_url":"https://api.github.com/users/josharian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josharian/subscriptions","organizations_url":"https://api.github.com/users/josharian/orgs","repos_url":"https://api.github.com/users/josharian/repos","events_url":"https://api.github.com/users/josharian/events{/privacy}","received_events_url":"https://api.github.com/users/josharian/received_events","type":"User","site_admin":false},"open_issues":327,"closed_issues":123,"state":"open","created_at":"2015-05-05T02:39:06Z","updated_at":"2015-09-15T02:46:38Z","due_on":"2016-01-31T08:00:00Z","closed_at":null},"comments":12,"created_at":"2015-09-12T08:29:31Z","updated_at":"2015-09-15T08:09:53Z","closed_at":null,"body":"**Updated Sep 14:** Added Samsung Grand Prime and Chuwi Vi8 to working device list.\r\n\r\nGo ver: devel +0b5bcf5 Sat Sep 12 08:34:52 2015 +0000 linux/amd64\r\nGo Mobile ver:  +65551d8 Fri Sep 11 20:14:45 2015 +0000 (android); androidSDK=/opt/Android/Sdk/platforms/android-23\r\nAndroid Studio ver: 1.4 Beta3\r\nGo Mobile Bind Plugin: 0.2.2\r\nBuild Env: Linux x86_64\r\n\r\nProblem:\r\n------------\r\n\r\nTCP networking code generated for Android packaged as .so in APK with studio and go-bind plugin will sometimes work, and most often times, result in \"protocol not available\" error in net.Dial().\r\n\r\n```\r\ndial tcp 173.205.184.7:80: protocol not available\r\n```\r\n\r\nSetup:\r\n---------\r\n1) Manifest has   ```xml <uses-permission android:name=\"android.permission.INTERNET\" /> ```\r\n2) Java tcp does work, verified in same apk. \r\n3) Tested both calling go via java using go-bind bridge on java main thread and java background thread. Result is the same. \r\n\r\nExpectation:\r\n------------------\r\n* From NDK docs, native libraries should inherit rights from java/manifest and it should have access to TCP protocol at least. \r\n* Also did not expect some devices to work while most devices failed. If there is a permission issue, it should either all work or all fail.\r\n\r\nTest Code:\r\n--------------\r\nAt the bottom I have included the Go code and relevant Java code you can insert into any go mobile android  project. \r\n\r\nWorking Devices:\r\n* Asus Zenfone2 (5.0) (x86 devices but runs the generated armv7 .so via libhoudini just fine)\r\n* Chuwi VL8 Tablet (4.4.4) Mediatek arm9 cpu\r\n* Samsung Grand Prime SM-G5308W (4.4.4)\r\n* Chuwi Vi8 Tablet (4.4.4) (x86 device...)\r\n\r\nFailed Devices:\r\n* Lollipop API 22 armv7 Emulator\r\n* Samsung SM-T320 (CM 5.1.1)\r\n* Samsung GT-N7102 (4.3)\r\n* Samsung T807T (4.4.2)\r\n* Samsung Galaxy S5 (5.1.1)\r\n* Nexus 7 (5.1.1)\r\n* LG G3 D851 (5.0.1)\r\n* OnePlus (CM 4.4.4)\r\n\r\nI will try to update the device list with working/non-working as I find more devices to test on. \r\n\r\n```go\r\n\r\npackage gosocket\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"net\"\r\n\t\"strconv\"\r\n\t\"strings\"\r\n)\r\n\r\n//in java call this and pass host, and port\r\nfunc GetTestResult(h string, p int) {\r\n\tconst ERR_PROTOCOL_NOT_AVAILABLE = \"protocol not available\"\r\n\r\n\tdst := h + \":\" + strconv.Itoa(p)\r\n\r\n\tfmt.Println(\"Starting go test...\", dst)\r\n\r\n\tch := make(chan struct{}, 0)\r\n\r\n\t//test TCP dial in go routines....\r\n\tfor i := 0; i < 5; i++ {\r\n\r\n\t\tgo func(ch chan struct{}) {\r\n\t\t\t_, err := net.Dial(\"tcp\", dst)\r\n\r\n\t\t\tif err != nil && strings.Contains(err.Error(), ERR_PROTOCOL_NOT_AVAILABLE) {\r\n\t\t\t\tfmt.Println(err)\r\n\t\t\t} else {\r\n\t\t\t\tfmt.Println(\"GOT TCP!\")\r\n\r\n\t\t\t\t//err is fine as long as it is not ERR_PROTOCOL_NOT_AVAILABLE\r\n\t\t\t\tif err != nil {\r\n\t\t\t\t\tfmt.Println(\"With Err:\", err)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tfmt.Println(\"completed tcp go routine..\")\r\n\r\n\t\t\tch <- struct{}{}\r\n\t\t}(ch)\r\n\r\n\t\t<-ch\r\n\t}\r\n\r\n\t//test TCP dial in plain serial....\r\n\tfor i := 0; i < 5; i++ {\r\n\r\n\t\t_, err := net.Dial(\"tcp\", dst)\r\n\r\n\t\tif err != nil && strings.Contains(err.Error(), ERR_PROTOCOL_NOT_AVAILABLE) {\r\n\t\t\tfmt.Println(err)\r\n\t\t} else {\r\n\t\t\tfmt.Println(\"GOT TCP!\")\r\n\r\n\t\t\t//err is fine as long as it is not ERR_PROTOCOL_NOT_AVAILABLE\r\n\t\t\tif err != nil {\r\n\t\t\t\tfmt.Println(\"With Err:\", err)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfmt.Println(\"completed tcp serial..\")\r\n\r\n\t}\r\n}\r\n\r\n```\r\n\r\n```java\r\n@Override\r\n    protected void onStart() {\r\n        super.onStart();\r\n\r\n        //CHANGE ME....\r\n        String host = \"173.205.184.7\";\r\n        int port = 80;\r\n\r\n        Log.d(\"xing\", \"about to call go in main thread...\");\r\n\r\n        //call go in main thread\r\n        Gosocket.GetTestResult(host, port);\r\n\r\n        Thread r = new Thread() {\r\n\r\n            @Override\r\n            public void run() {\r\n                android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);\r\n\r\n\r\n                Log.d(\"xing\", \"about to call go in background...\");\r\n\r\n                //call go in background thread...\r\n                Gosocket.GetTestResult(host, port);\r\n            }\r\n        };\r\n\r\n        r.start();\r\n\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/140315727","html_url":"https://github.com/golang/go/issues/12598#issuecomment-140315727","issue_url":"https://api.github.com/repos/golang/go/issues/12598","id":140315727,"user":{"login":"eliasnaur","id":524812,"avatar_url":"https://avatars.githubusercontent.com/u/524812?v=3","gravatar_id":"","url":"https://api.github.com/users/eliasnaur","html_url":"https://github.com/eliasnaur","followers_url":"https://api.github.com/users/eliasnaur/followers","following_url":"https://api.github.com/users/eliasnaur/following{/other_user}","gists_url":"https://api.github.com/users/eliasnaur/gists{/gist_id}","starred_url":"https://api.github.com/users/eliasnaur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eliasnaur/subscriptions","organizations_url":"https://api.github.com/users/eliasnaur/orgs","repos_url":"https://api.github.com/users/eliasnaur/repos","events_url":"https://api.github.com/users/eliasnaur/events{/privacy}","received_events_url":"https://api.github.com/users/eliasnaur/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T08:09:53Z","updated_at":"2015-09-15T08:09:53Z","body":"Awesome testing coverage! :) I'm not sure you mentioned it, but is there any indication of a timing issue? That is, have you ever had a configuration fail and then suddenly succeed efter some number of retries?"}}