google / nearby

🐿️ A collection of projects focused on connectivity that enable building cross-device experiences.
https://developers.google.com/nearby
Apache License 2.0
725 stars 153 forks source link

Request connection error #2666

Open yerzhant opened 2 months ago

yerzhant commented 2 months ago

Project

Nearby Connections

Language

Other

OS Platform

Linux

What happened?

With this code:

    private val endpointDiscoveryCallback = object : EndpointDiscoveryCallback() {
        override fun onEndpointFound(
            endpoint: String,
            discoveredEndpointInfo: DiscoveredEndpointInfo
        ) {
            remoteEndpoint = endpoint
            client.requestConnection(
                "Receiver",
                endpoint,
                discovererConnectionCallback
            )
                .addOnSuccessListener { client.stopDiscovery() }
                .addOnFailureListener { Log.e(logTag, "Failed to request a connection", it) }
        }

        override fun onEndpointLost(endpoint: String) {
            Log.e(logTag, "Endpoint $endpoint lost")
        }
    }

    override fun discover() {
        val options = DiscoveryOptions.Builder().setStrategy(P2P_POINT_TO_POINT).build()
        client.startDiscovery(serviceId, endpointDiscoveryCallback, options)
            .addOnFailureListener { Log.e(logTag, "Discovery failed", it) }
    }

First run is fine but the second and further ones return this error:

E/NearByService(31054): Failed to request a connection
E/NearByService(31054): com.google.android.gms.common.api.ApiException: 13: ERROR
E/NearByService(31054):     at com.google.android.gms.internal.nearby.zzdo.setFailedResult(com.google.android.gms:play-services-nearby@@19.2.0:1)
E/NearByService(31054):     at com.google.android.gms.internal.nearby.zzce.zzb(com.google.android.gms:play-services-nearby@@19.2.0:4)
E/NearByService(31054):     at com.google.android.gms.internal.nearby.zzfr.zza(com.google.android.gms:play-services-nearby@@19.2.0:3)
E/NearByService(31054):     at com.google.android.gms.internal.nearby.zzb.onTransact(com.google.android.gms:play-services-nearby@@19.2.0:3)
E/NearByService(31054):     at android.os.Binder.execTransactInternal(Binder.java:1380)
E/NearByService(31054):     at android.os.Binder.execTransact(Binder.java:1311)

What did you expect to happen?

Request connection should succeed.

How can we reproduce it (as minimally and precisely as possible)?

Try to discover like this:

    private val endpointDiscoveryCallback = object : EndpointDiscoveryCallback() {
        override fun onEndpointFound(
            endpoint: String,
            discoveredEndpointInfo: DiscoveredEndpointInfo
        ) {
            remoteEndpoint = endpoint
            client.requestConnection(
                "Receiver",
                endpoint,
                discovererConnectionCallback
            )
                .addOnSuccessListener { client.stopDiscovery() }
                .addOnFailureListener { Log.e(logTag, "Failed to request a connection", it) }
        }

        override fun onEndpointLost(endpoint: String) {
            Log.e(logTag, "Endpoint $endpoint lost")
        }
    }

    override fun discover() {
        val options = DiscoveryOptions.Builder().setStrategy(P2P_POINT_TO_POINT).build()
        client.startDiscovery(serviceId, endpointDiscoveryCallback, options)
            .addOnFailureListener { Log.e(logTag, "Discovery failed", it) }
    }

How often does this bug happen?

Often

Standalone code to reproduce the issue

No response

Relevant log output

No response

Anything else we need to know?

No response

yerzhant commented 2 months ago

One must not that this can be reset by switching on and off flight mode.

yerzhant commented 2 months ago

The issue also disappears if the other (advertising) party switches flight mode on. If the advertising party switches flight mode off the issue arises again.

yerzhant commented 2 months ago

On trying to discover a second time one can see in logs these errors:

2024-06-30 19:56:52.776 15057-7489  NearbyMediums           com.google.android.gms.persistent    E  MEDIUM_ERROR [SYSTEM][WIFI_LAN][CONNECT][ESTABLISH_CONNECTION_FAILED][UNKNOWN], service-id=com.example.nbs
2024-06-30 19:56:52.797 15057-7489  NearbyMediums           com.google.android.gms.persistent    E  MEDIUM_ERROR [SYSTEM][WIFI_LAN][CONNECT][ESTABLISH_CONNECTION_FAILED][UNKNOWN], service-id=com.example.nbs
2024-06-30 19:56:52.807 15057-7489  NearbyMediums           com.google.android.gms.persistent    E  MEDIUM_ERROR [SYSTEM][WIFI_LAN][CONNECT][ESTABLISH_CONNECTION_FAILED][UNKNOWN], service-id=com.example.nbs