Not 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.
Network request API: targets apps that need to connect to a peer device, such as when configuring an IoT device or transferring files to a camera. In such cases, the peer device starts up a SoftAP and the API allows the app to guide the user to connect to the device. The resulting network is not intended to provide internet access, can't be used by the system, and can't be used by any app except the configuring app.
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 calling syscall.Connect() on that, but it fails with network unreachable just the same as it does via net.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
dial tcp 192.168.0.1:80: connect: network is unreachable
opening a TCP socket fails.
The text was updated successfully, but these errors were encountered: