x/mobile: network unreachable on Android 10+ via Network request API #52702
Labels
mobile
Android, iOS, and x/mobile
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Note:
gomobile
version extracted fromgo.mod
file.Does this issue reproduce with the latest release?
I would say yes, I tried installing
go1.18.1
and aliasinggo
to that in one terminal instance, butgomobile
is the underlying CLI that builds the aar and that is the latest version.What operating system and processor architecture are you using (
go env
)?go env
OutputNot sure if
go env
is relevant when talking about Android, but included anyway.What did you do?
We have a lib written in go that we compile via
gomobile
into an aar and use in our android application. When we connect to a Wi-Fi network via Android's Network request API on Android 10 and up, we cannot initiate a TCP connection from the go code.According to Android's Wi-Fi infrastructure overview
The problem seems to be that the OS does not recognize the go code as part of the application, but I'm not 100% sure either. We have even tried opening a socket via
syscall.Socket()
then callingsyscall.Connect()
on that, but it fails withnetwork unreachable
just the same as it does vianet.Dial()
.If you connect the phone to the Wi-Fi in question via Settings (i.e. not using the Network request API), then everything works without issue.
The weird thing is that we have another team working with C++ and boost, and they also generate JNI bindings for their native code, but in their case using the Network request API works, so the OS recognizes that code as part of the app and lets it open their sockets. For go, though, it does not, even though the code is running in the same process (
Getpid
return the same PID both in the go code as well as the native android code).I have made a minimal reproduction repository where you can observe the behavior: https://github.com/myklosbotond/tcp-unreachable-repro . It only works with android 10 and up and it's important to disable cellular data before the tests. We tested on multiple android versions and on phones from multiple brands, and the bug is present in every case.
What did you expect to see?
Network calls can be done via the Wi-Fi bound to the app.
What did you see instead?
Requests are always failing with
opening a TCP socket fails.
The text was updated successfully, but these errors were encountered: