UDP NWConnection fails on fragmentation

We're writing a Network.framework version of our peer-to-peer video streaming implementation, and are running into issues when the UDP message size becomes large enough to cause fragmentation. When this happens, it fails to reassemble with the following error:


nw_protocol_ipv6_process_reassembly [C5.1:2] Failed to reassemble IPv6 Fragmentation ID 4293396248, dropping 1 frames


This happens both over en0 and awdl0. Any insights as to why this is happening would be greatly appreciated!

Accepted Reply

We're writing a Network.framework version of our peer-to-peer video streaming implementation …

You really want to try to avoid UDP fragmentation, especially for a video streaming app. It causes many problems:

  • Each extra fragment doubles the chance of the whole datagram getting lost.

  • Reassembling the fragments is expensive.

  • Network infrastructure often sends fragments via the slow path.

A better approach is to implement your own segmentation so that each of your UDP datagrams is below the path MTU. If “peer-to-peer” means “only on the local network”, you can use

nw_connection_get_maximum_datagram_size
to get the MTU. If not, you’ll have to do path MTU discovery.

Having said that, there are specific situations where large UDP datagrams are unavoidable (for example, when dealing with IKEv2 peers that don’t support RFC 7383), so it’s clear that the Network framework should deal with this. Various folks have filed bugs about this and the problem should be fixed in the currently seeded major OS releases (r. 45766979).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

We're writing a Network.framework version of our peer-to-peer video streaming implementation …

You really want to try to avoid UDP fragmentation, especially for a video streaming app. It causes many problems:

  • Each extra fragment doubles the chance of the whole datagram getting lost.

  • Reassembling the fragments is expensive.

  • Network infrastructure often sends fragments via the slow path.

A better approach is to implement your own segmentation so that each of your UDP datagrams is below the path MTU. If “peer-to-peer” means “only on the local network”, you can use

nw_connection_get_maximum_datagram_size
to get the MTU. If not, you’ll have to do path MTU discovery.

Having said that, there are specific situations where large UDP datagrams are unavoidable (for example, when dealing with IKEv2 peers that don’t support RFC 7383), so it’s clear that the Network framework should deal with this. Various folks have filed bugs about this and the problem should be fixed in the currently seeded major OS releases (r. 45766979).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I also get this error using NWConnection and UDP

I can see the disableFragmentation boolean property but have no way to access it. How do you disable fragmentation completely?

I can see the disableFragmentation boolean property but have no way to access it.

I presume you’re referring to this. What do you mean by “no way to access it”? It’s a read/write property, so just set it as part of your connection setup prior to calling start(queue:).

Share and Enjoy

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