Unrelated 3rd party apps interfering with NWConnectionGroup's state

Description:

Using the Network framework, SDDP discovery will fail while 3rd party apps are running in the background

The 3rd party apps in question are (presumably) using the CocoaAsyncSocket library to perform SSDP discoveries on WiFi.

How to reproduce

Test Setup:

For the 3rd party app, you can use https://apps.apple.com/us/app/web-video-cast-browser-to-tv/id1400866497

The simplistic test app referenced below can be installed from: https://github.com/tifroz/SSDPTest

You must have the multicast entitlement (https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_networking_multicast)

Test steps:

  1. On the test device, install a 3rd party app that uses the CocoaAsyncSocket library to performs SSDPdiscovery.
  2. Restart the test device to clear any existing 3rd party apps/processes
  3. Run this test app on the device, the status should be ready
  4. Kill the test app
  5. Start the 3rd party app that uses the CocoaAsyncSocket library, then send it to the background (without killing it) after a few seconds
  6. Start the test app, this time the status should be (failed, address already in use)
  7. Optionally, kill the test app + the 3rd party app, then start the test app again (status should be ready)

Question:

Is there a workaround?

Are you setting the allowLocalEndpointReuse property?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Yes allowLocalEndpointReuse is set to true

Here is the entire code from the test app in the GitHub repository

import Foundation
import UIKit
import Network

class ViewController: UIViewController {

  @IBOutlet weak var stateLabel: UILabel!
  var connectionGroup: NWMulticastGroup!

  override func viewDidLoad() {

    super.viewDidLoad()

    let multicastGroup = try! NWMulticastGroup(for: [ .hostPort(host: "239.255.255.250", port: 1900) ])
    let parameters = NWParameters.udp
    parameters.allowLocalEndpointReuse = true
    let connectionGroup = NWConnectionGroup(with: multicastGroup, using: .udp)
    stateLabel.text = "\(connectionGroup.state)"
    connectionGroup.setReceiveHandler(maximumMessageSize: 16384, rejectOversizedMessages: true) { message, content, isComplete in
      NSLog("Received \(content?.count ?? 0) bytes from \(String(describing: message.remoteEndpoint))")
    }
    connectionGroup.stateUpdateHandler = { newState in
      NSLog("Group entered state \(String(describing: newState))")
      self.stateLabel.text = "\(newState)"
    }
    connectionGroup.start(queue: .main)
  }
}

If you put your SSDP code into a second test app, does it cause the same interference?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Yes after cloning the test app, same interference. The first opened app will be in status ready, and the app started subsequently will show the error status failed(POSIXErrorCode ....address already in use)

I talked with the Network framework folks about this and, well, the question as to whether this should word depends on your definition of “should”:

  • As things are currently implemented, we don’t expect this to work.

  • OTOH, I think it’s reasonable to expect this to work, especially given that you can do the same thing with BSD Sockets.

Please file a bug about this, then post your bug number here, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks Quinn! With the understanding that we can't reasonably ask users to kill 3rd party apps, this means that using the Network framework to implement an SSDP client is not recommended at this time? I just want to be clear that there isn't a Network way to implement the SSDP client that I somehow missed.

Here is the bug# FB11642799 (SSDP clients broken by unrelated 3rd party apps)

I just want to be clear that there isn't a Network way to implement the SSDP client that I somehow missed.

Not that I can think of.

Here is the bug# FB11642799

Ta!

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Is there any way I can check the status of this bug? Has this been resolved in iOS 17?

For posterity, I implemented similar code to the above on macOS Sonoma 14.0 (23A344) and got the same address already in use error :/

Is there any way I can check the status of this bug?

Not directly, but you can do this indirectly by filing a dup. I talked about this in Bug Reporting: How and Why?.

Has this been resolved in iOS 17?

No.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Unrelated 3rd party apps interfering with NWConnectionGroup's state
 
 
Q