[NSURLSessionWebSocketTask sendPingWithPongReceiveHandler:] on iOS does not seem to call the completion handler when called twice in a row with an intervening call to send or receive a message.
Here is a minimal reproduction from an Objective-C project.
- (void)viewDidLoad {
[super viewDidLoad];
NSURLSession* session = [NSURLSession sharedSession];
NSURLSessionWebSocketTask* task = [session webSocketTaskWithRequest: [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"wss://ws.postman-echo.com/raw"]]];
[task resume];
[task sendPingWithPongReceiveHandler:^(NSError * _Nullable error) {
printf("Got ping 1\n"); /* We will get to this line. */
[task sendPingWithPongReceiveHandler:^(NSError * _Nullable error) {\
printf("Got ping 2\n"); /* We will *not* get to this line. */
}];
}];
}
Using WireShark, I can verify that NSURLSession sends two pings and that the server responds with two pongs. But the callback handler does not get called after the second pong.
Does anyone have an suggestions on what I could be doing wrong?