Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry logic for Wi-Fi LAN advertising to avoid issues on iOS 14.8.1 #2061

Open
edgarclerigo opened this issue Aug 10, 2023 · 7 comments
Open
Assignees
Labels
lang: swift An issue with a Swift client library P1 Priority 1 issue (will likely block a customer in the future) platform: apple An issue with the macOS or iOS implementation project: connections An issue with the Connections project type: bug Something is broken or not working as intended

Comments

@edgarclerigo
Copy link

I'm currently using the latest version of the Nearby SPM.

The exact same code runs ok, and I'm able to startAdvertising on iOS 16.6 but on iOS 14.8.1 it fails to start.

These are the logs that I have

[lvl=2] service_controller_router.cc:85() ServiceControllerRouter going up.
[lvl=2] client_proxy.cc:60() ClientProxy ctor event_logger=0x0
[lvl=2] analytics_recorder.cc:101() Start AnalyticsRecorder ctor event_logger_=0x0
[lvl=2] endpoint_manager.cc:377() EndpointManager received request to add registration of frame processor 0x12c0256b0 for frame type PAYLOAD_TRANSFER, self=0x12c025638
[lvl=2] endpoint_manager.cc:377() EndpointManager received request to add registration of frame processor 0x12c0257b8 for frame type BANDWIDTH_UPGRADE_NEGOTIATION, self=0x12c025638
[lvl=2] offline_service_controller.cc:41() Client -2222247868050356217 requested advertising to start.
[lvl=2] base_pcp_handler.cc:179() StartAdvertising with supported mediums: { WIFI_LAN }
[lvl=2] p2p_cluster_pcp_handler.cc:2055() P2pClusterPcpHandler::StartWifiLanAdvertising: service=myserviceid: start
[lvl=2] base_pcp_handler.cc:432() Waiting for future to complete: StartAdvertising(myserviceid)
[lvl=2] wifi_lan.cc:242() Failed to start accepting WifiLan connections for service_id=myserviceid
[lvl=2] p2p_cluster_pcp_handler.cc:2064() In StartWifiLanAdvertising(6970686f6e652038), client=-2222247868050356217 failed to start listening for incoming WifiLan connections to service_id=myserviceid
[lvl=3] p2p_cluster_pcp_handler.cc:174() Failed StartAdvertising(6970686f6e652038) for client=-2222247868050356217
[lvl=2] client_proxy.cc:932() ClientProxy [ExitHighVisibilityMode]: client=-2222247868050356217
[lvl=2] base_pcp_handler.cc:439() Future:[StartAdvertising(myserviceid)] completed with status:12
@edgarclerigo edgarclerigo added needs-triage Issue still needs to be assigned, labeled and deduplicated type: question General questions (we may not have time to provide an answer) labels Aug 10, 2023
@bourdakos1 bourdakos1 added P1 Priority 1 issue (will likely block a customer in the future) type: bug Something is broken or not working as intended platform: apple An issue with the macOS or iOS implementation lang: swift An issue with a Swift client library project: connections An issue with the Connections project and removed type: question General questions (we may not have time to provide an answer) needs-triage Issue still needs to be assigned, labeled and deduplicated labels Aug 10, 2023
@bourdakos1 bourdakos1 self-assigned this Aug 10, 2023
@edgarclerigo
Copy link
Author

@bourdakos1 forgot to tell that the startDiscovery is working as expected

@bourdakos1
Copy link
Collaborator

bourdakos1 commented Aug 10, 2023

It looks like it failed to start listening for incoming connections, but the system didn't return any an explicit errors. My best guess is that the listener transitioned to the nw_listener_state_waiting which isn't a fatal error, but will end in a fatal nearby error, since we don't attempt retries: https://developer.apple.com/documentation/network/nw_listener_state_t/nw_listener_state_waiting?language=objc

However, I don't have an iOS 14.8.1 device to verify. Do you mind trying to add some logs here:

to see what state the listener is in?

I can also push an update with more logs if thats easier, but that might take some time to get reviewed/submitted

@edgarclerigo
Copy link
Author

It looks like your guessing is correct,
Screenshot 2023-08-10 at 20 57 25
Screenshot 2023-08-10 at 20 57 27

@bourdakos1
Copy link
Collaborator

Thanks for verifying! I need to look into how to properly handle this case

@edgarclerigo
Copy link
Author

I made this workaround

private func startAdvertise(nearbyMessage: NearbyMessage, retryCount: Int) {
        print("[NearbyManager] Retrying startAdvertise: \(retryCount)")

        guard
            let nearbyMessageData = nearbyMessage.dataValue,
            retryCount > 0
        else {
            return
        }

        advertiser.startAdvertising(
            using: nearbyMessageData,
            completionHandler: { error in
                guard let error = error else {
                    print("[NearbyManager] Success on startAdvertising")
                    return
                }

                print("[NearbyManager] Failed to advertise: \(error.localizedDescription)")

                let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { [weak self] timer in
                    self?.startAdvertise(nearbyMessage: nearbyMessage, retryCount: retryCount-1)
                }
                timer.fire()
            }
        )
    }

Eventually it will work:

[NearbyManager] Retrying startAdvertise: 10
[NearbyManager] Failed to advertise: The operation couldn’t be completed. (com.google.nearby.connections.error error 11.)
[NearbyManager] Retrying startAdvertise: 9
[NearbyManager] Failed to advertise: The operation couldn’t be completed. (com.google.nearby.connections.error error 11.)
[NearbyManager] Retrying startAdvertise: 8
[NearbyManager] Success on startAdvertising

@bourdakos1
Copy link
Collaborator

Awesome! So it is just a matter of retrying. I'll update this issue to reflect the need for adding internal retry logic for Wi-Fi LAN

@bourdakos1 bourdakos1 changed the title startAdvertising on iOS 14.8.1 Add retry logic for Wi-Fi LAN advertising to avoid issues on iOS 14.8.1 Aug 10, 2023
@edgarclerigo
Copy link
Author

Thanks for answering so fast! I will keep subscribed on this issue so we can update the lib on our end :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: swift An issue with a Swift client library P1 Priority 1 issue (will likely block a customer in the future) platform: apple An issue with the macOS or iOS implementation project: connections An issue with the Connections project type: bug Something is broken or not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants