CFNetworking warnings/errors indicating race conditions
bug
**Describe the bug**
There seem to be race conditions in the networking code. For example: There are sporatic failures during connection.
```
nw_socket_copy_info [C5.1.1:3] Can't get TCP_INFO on a multipath socket
nw_socket_copy_info [C5.1.1:3] Can't get TCP_CONNECTION_INFO on a multipath socket
Connection 5: received failure notification
nw_read_request_report [C5] Receive failed with error "Socket is not connected"
nw_flow_service_reads [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] No output handler
nw_read_request_report [C5] Receive failed with error "Socket is not connected"
nw_flow_service_reads [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] No output handler
nw_flow_add_write_request [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] cannot accept write requests
nw_write_request_report [C5] Send failed with error "Socket is not connected"
nw_flow_add_write_request [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] cannot accept write requests
nw_write_request_report [C5] Send failed with error "Socket is not connected"
Task <5F713FE5-7C2C-49EA-B960-4E9691D25D4C>.<1> finished with error [57] Error Domain=NSPOSIXErrorDomain Code=57 "Socket is not connected" UserInfo={NSDescription=Socket is not connected, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalWebSocketTask <5F713FE5-7C2C-49EA-B960-4E9691D25D4C>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalWebSocketTask <5F713FE5-7C2C-49EA-B960-4E9691D25D4C>.<1>}
nw_flow_add_write_request [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] cannot accept write requests
nw_write_request_report [C5] Send failed with error "Socket is not connected"
```
**SDK Version**
branch/main
8203ef6150156e
**iOS/macOS Version**
iOS 26.3.1
(This is just my test device. It doesn't seem to be specific to this version.)
**Xcode Version**
Xcode 26.2
Swift 5.9
**Steps to Reproduce**
connect() to a livekit cloud server.
**Expected behavior**
No CFNetworking (`nw_*`) errors/warnings are visble.
**Screenshots**
N/A
**Logs**
Ran with environment variable `CFNETWORK_DIAGNOSTICS` with value of `3`.
```
m.connect(url:token:connectOptions:roomOptions:) Connecting to room...
Room.connect(url:token:connectOptions:roomOptions:) Connecting to room...
nw_socket_copy_info [C6.1.1:3] Can't get TCP_INFO on a multipath socket
nw_socket_copy_info [C6.1.1:3] Can't get TCP_CONNECTION_INFO on a multipath socket
Room.signalClient(_:didReceiveConnectResponse:) ServerInfo(edition: cloud, version: 1.9.12, protocol: 16, region: Germany 2, nodeID: NM_OFRANKFURT1B_ZfPX4ApdxTyp, debugInfo: )
Room.signalClient(_:didReceiveConnectResponse:) ServerInfo(edition: cloud, version: 1.9.12, protocol: 16, region: Germany 2, nodeID: NM_OFRANKFURT1B_ZfPX4ApdxTyp, debugInfo: )
nw_socket_copy_info [C5.1.1:3] Can't get TCP_INFO on a multipath socket
nw_socket_copy_info [C5.1.1:3] Can't get TCP_CONNECTION_INFO on a multipath socket
Connection 5: received failure notification
nw_read_request_report [C5] Receive failed with error "Socket is not connected"
nw_flow_service_reads [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] No output handler
nw_read_request_report [C5] Receive failed with error "Socket is not connected"
nw_flow_service_reads [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] No output handler
nw_flow_add_write_request [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] cannot accept write requests
nw_write_request_report [C5] Send failed with error "Socket is not connected"
nw_flow_add_write_request [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] cannot accept write requests
nw_write_request_report [C5] Send failed with error "Socket is not connected"
Task <5F713FE5-7C2C-49EA-B960-4E9691D25D4C>.<1> finished with error [57] Error Domain=NSPOSIXErrorDomain Code=57 "Socket is not connected" UserInfo={NSDescription=Socket is not connected, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalWebSocketTask <5F713FE5-7C2C-49EA-B960-4E9691D25D4C>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalWebSocketTask <5F713FE5-7C2C-49EA-B960-4E9691D25D4C>.<1>}
nw_flow_add_write_request [C5 161.115.161.158:443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] cannot accept write requests
nw_write_request_report [C5] Send failed with error "Socket is not connected"
Delegate.urlSession(_:task:didCompleteWithError:) didCompleteWithError: Optional(Error Domain=NSPOSIXErrorDomain Code=57 "Socket is not connected" UserInfo={NSDescription=Socket is not connected, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalWebSocketTask <5F713FE5-7C2C-49EA-B960-4E9691D25D4C>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalWebSocketTask <5F713FE5-7C2C-49EA-B960-4E9691D25D4C>.<1>})
SignalClient._requestQueue Failed to send queued request LiveKit.Livekit_SignalRequest:
trickle {
candidateInit: "{\"candidate\":\"candidate:552710961 1 udp 1685921535 194.15.154.77 5623 typ srflx raddr 192.168.178.71 rport 55068 generation 0 ufrag igmd network-id 1 network-cost 10\",\"sdpMLineIndex\":0,\"sdpMid\":\"0\"}"
target: SUBSCRIBER
}
with error: Error Domain=NSPOSIXErrorDomain Code=57 "Socket is not connected" UserInfo={NSDescription=Socket is not connected}
SignalClient._requestQueue Failed to send queued request LiveKit.Livekit_SignalRequest:
trickle {
candidateInit: "{\"candidate\":\"candidate:2000116897 1 udp 1685921535 194.15.154.77 5624 typ srflx raddr 192.168.178.71 rport 62981 generation 0 ufrag Bly+ network-id 1 network-cost 10\",\"sdpMLineIndex\":0,\"sdpMid\":\"0\"}"
}
with error: Error Domain=NSPOSIXErrorDomain Code=57 "Socket is not connected" UserInfo={NSDescription=Socket is not connected}
SignalClient._sendRequest(_:) connectionState is .disconnected
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
SignalClient._sendRequest(_:) connectionState is .disconnected
Room.transport(_:didGenerateIceCandidate:) Failed to send iceCandidate, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state(connectionState is .disconnected)" UserInfo={NSLocalizedDescription=Invalid state(connectionState is .disconnected)}
Room.signalClient(_:didReceiveConnectResponse:) ServerInfo(edition: cloud, version: 1.9.12, protocol: 16, region: Germany 2, nodeID: NM_OFRANKFURT1B_ZfPX4ApdxTyp, debugInfo: )
nw_socket_copy_info [C8.1.1:3] Can't get TCP_INFO on a multipath socket
nw_socket_copy_info [C8.1.1:3] Can't get TCP_CONNECTION_INFO on a multipath socket
Room.signalClient(_:didReceiveConnectResponse:) ServerInfo(edition: cloud, version: 1.9.12, protocol: 16, region: Germany 2, nodeID: NM_OFRANKFURT1B_ZfPX4ApdxTyp, debugInfo: )
"didUpdateConnectionState: .connecting -> .connected"
[Retry] Attempt 1 of 3, delay: 0.2
LocalParticipant._publish(track:options:) [publish] LocalAudioTrack(sid: nil, name: microphone, source: microphone) options: Optional(<LiveKit.AudioPublishOptions: 0x1250468c0>)...
Track.start() Already started
LocalParticipant._publish(track:options:) [publish] LocalAudioTrack(sid: nil, name: microphone, source: microphone) options: Optional(<LiveKit.AudioPublishOptions: 0x125046880>)...
Track.start() Already started
"🎙️ LiveKit audio track published (recording active): sid=TR_AMZgAdegSgCbaN, source=microphone, muted=false"
LocalParticipant._publish(track:options:) [publish] success LocalTrackPublication(sid: TR_AMZgAdegSgCbaN, kind: Kind(rawValue: 0), source: microphone)
Room.connect(url:token:connectOptions:roomOptions:) Connected to Room(sid: Optional(RM_bwQGZ2svjwFL), name: cfcc4061-7ac2-4b23-a36d-16f6605b9e63, serverVersion: 1.9.12, serverRegion: Germany 2)
"📝 LiveKit text stream handler registered for topic: lk.transcription"
"🎙️ LiveKit audio recording enabled: microphone=true, localAudioTracks=1"
"room id: RM_bwQGZ2svjwFL name: cfcc4061-7ac2-4b23-a36d-16f6605b9e63"
"📡 LiveKit audio being sent: remote subscribed to local audio track sid=TR_AMZgAdegSgCbaN"
IncomingStreamManager.openStream(with:from:) Unable to find handler for incoming stream: 3ce0d5da-f360-42d0-b342-99980fa690ce, topic: lk.agent.events, opened by: agent-AJ_RfGoq2Ne8XNt
LocalParticipant._publish(track:options:) [publish] failed LocalAudioTrack(sid: nil, name: microphone, source: microphone), error: Error Domain=io.livekit.swift-sdk Code=101 "Timed out" UserInfo={NSLocalizedDescription=Timed out}
Track.stop() Already stopped
nw_socket_copy_info [C9.1.1:3] Can't get TCP_INFO on a multipath socket
nw_socket_copy_info [C9.1.1:3] Can't get TCP_CONNECTION_INFO on a multipath socket
[Retry] Attempt 1 of 10, delay: 0.3187575866921498
[Retry] Waiting for 0.3187575866921498 seconds...
Room.startReconnect(reason:nextReconnectMode:) [Connect] Reconnect mode: .quick failed with error: Error Domain=io.livekit.swift-sdk Code=201 "WebRTC error(Failed to set configuration)" UserInfo={NSLocalizedDescription=WebRTC error(Failed to set configuration)}
"didUpdateConnectionState: .connected -> .disconnected"
"🔥 connect failed: Error Domain=io.livekit.swift-sdk Code=101 \"Timed out\" UserInfo={NSLocalizedDescription=Timed out}"
"Error: unable to connect: Error Domain=io.livekit.swift-sdk Code=101 \"Timed out\" UserInfo={NSLocalizedDescription=Timed out}"
"Error: unable to set microphone enabled if not connected: .disconnected"
AsyncCompleter<()>.resume(throwing:) Participant active
AsyncCompleter<()>.resume(throwing:) Participant active
[Retry] Attempt 2 of 10, delay: 3.5795339681913885
"didUpdateConnectionState: .disconnected -> .connected"
nw_socket_copy_info [C11.1.1:3] Can't get TCP_INFO on a multipath socket
nw_socket_copy_info [C11.1.1:3] Can't get TCP_CONNECTION_INFO on a multipath socket
Connection 11: received failure notification
nw_read_request_report [C11] Receive failed with error "Socket is not connected"
nw_flow_service_reads [C11 2603:c020:8017:2701:0:e786:d19c:5a32.443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] No output handler
nw_flow_add_write_request [C11 2603:c020:8017:2701:0:e786:d19c:5a32.443 failed parent-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi, LQM: good)] cannot accept write requests
nw_write_request_report [C11] Send failed with error "Socket is not connected"
QueueActor<Livekit_SignalRequest>.clear() Clearing queue which is not empty
QueueActor<Livekit_SignalResponse>.clear() Clearing queue which is not empty
Room.startReconnect(reason:nextReconnectMode:) [Connect] Url or token is nil
Room.signalClient(_:didUpdateConnectionState:oldState:disconnectError:) Failed calling startReconnect, error: Error Domain=io.livekit.swift-sdk Code=104 "Invalid state" UserInfo={NSLocalizedDescription=Invalid state}
```
5 条评论