NSURLSessionWebSocketTask return bad address error

We receive bad address error

Error: (kNWErrorDomainPOSIX 错误 14 - Bad address),未能完成该操作。
Environment: iPhone 8#iOS#13.6#

from completion handler in

-[NSURLSessionWebSocketTask receiveMessageWithCompletionHandler:]

or

-[NSURLSessionWebSocketTask sendMessage:completionHandler:]

I'm not quit sure which one since their reporting error from same function in our code :(

===================================================

I was search information about

#define EFAULT          14              /* Bad address */

and socket, most of content telling me that we did not pass buffer to socket function properly. But NSURLSessionWebSocketTask has no method for me to manipulate underlying socket.

===================================================

We can not reproduce this error since it was reported from user device. Any possible reason that make this error happen?

But NSURLSessionWebSocketTask has no method for me to manipulate underlying socket.

Right. Getting a POSIX-level error out of NSURLSession is weird. Debugging this without being able to reproduce it in your office is going to be a challenge. Are you in touch with the user who is able to reproduce it?

Share and Enjoy

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

Hi @eskimo , thanks for replying and yes, it's really a challenge for us.

============================================

We have had a short touch with this user. He/she is facing a problem where he/she can't receive a specific kind of message for many days. However, he/she has said that the problem has been resolved after uninstalling and reinstalling our app. This means that this issue is highly relevant to our app's data environment.

============================================

My colleague from the server side has informed me that the user's websocket behavior is weird. It connects to our server, sends a normal message(deciding whether the client needs APNs or not), and immediately disconnects.

A typical log(from another user also encountering bad address error) looks like this below:

[2023-05-26 20:53:42:872][Call webSocketTaskWithRequest:] Create Task: LocalWebSocketTask <XYZ>.<1> withRequest: <NSMutableURLRequest: 0x2807d0480> { URL:  A_WS_URL}
[2023-05-26 20:53:42:872][Call receiveMessageWithCompletionHandler:] check&reconnect: create a new socket and resume, listen
[2023-05-26 20:53:43:083][Callback from URLSession:webSocketTask:didOpenWithProtocol:] Task: LocalWebSocketTask <XYZ>.<1>, didOpenWithProtocol (null)
[2023-05-26 20:53:43:083][Call bussinues code ]send push: needPush = 0, message = {"xx":"yy","zz":{"foo":"bar"}}
[2023-05-26 20:53:43:083][Call sendPingWithPongReceiveHandler] send ping
[2023-05-26 20:53:43:129][Callback from sendPingWithPongReceiveHandler:] receive pong success
[2023-05-26 20:53:43:154][Callback from receiveMessageWithCompletionHandler: ]handlerWebSocketTaskError: domain = kNWErrorDomainPOSIX, code = 14
[2023-05-26 20:53:43:154][Call cancel task since we encounter error, ]close&destory LocalWebSocketTask <XYZ>.<1>
[2023-05-26 20:53:43:154][Call bussinues code, try to reconnect later]start reconnect(timer: 0x282b9c180)
[2023-05-26 20:53:43:154][Callback from URLSession:webSocketTask:didCompleteWithError:] didComplete Task: LocalWebSocketTask <XYZ>.<1>
[2023-05-26 20:53:43:154]Callback from URLSession:webSocketTask:didCompleteWithError:] didComplete Error: Error Domain=kNWErrorDomainPOSIX Code=14 "Bad address" UserInfo={NSDescription=Bad address, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalWebSocketTask <XYZ>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalWebSocketTask <XYZ>.<1>}

============================================

We have received further information about this issue after viewing more than 25k error reports:

  1. Most of the errors are related to network circumstances, like timeouts, which is understandable.
  2. 0.3% of devices are reporting a "bad address" error from "receiveMessageWithCompletionHandler:" and "sendMessage:completionHandler:".
  3. 95% of the devices reporting a "bad address" are equipped with iOS 13.x.

============================================

We are planning to use the old websocket implementation on iOS 13 instead of NSURLSessionWebSocketTask if we could not address this issue. :p

Thansk for paying attention to this issue :)

NSURLSessionWebSocketTask return bad address error
 
 
Q