iOS 15 WKWebView websocket behaviour

Hello,

in our app we are reliant on a web socket inside a WKWebview. In previous releases this web socket worked well. In the iOS 15 betas though this web socket behaves differently: it connects to our server successfully but once the client tries to send any data through it the web socket throws an error and closes with a non descriptive error:

The operation couldn’t be completed. (kNWErrorDomainPOSIX error 54 - Connection reset by peer)

Looking into the system log the deepest error I can make out is:

nw_protocol_boringssl_error(1772) [C12.1.1:2][0x102e0d540] Lower protocol stack error post TLS handshake. [54: <private>]

A test web socket to another server seems to be working.

I also notices that a MitM proxy like Charles no longer shows web socket connections in the iOS 15 beta. This just indicates that something might have changed.

Because the communication via this socket is very important for the functionality of our app I must know what the issue is. I tried adding ATS exceptions for the URL of the socket to no avail.

Maybe this is a temporary bug in iOS 15 that will be fixed until its released? Or maybe anyone has experienced this kind of error in the past?

Problems like this, where code worked on a previous OS release but fails on a beta seed of a new OS, are always bugworthy. So, I recommend that you file a bug about this. Make sure to include a sysdiagnose log taken shortly after reproducing the problem.

Also, is the WebSocket server in question available on the public Internet? If so, include its URL in your bug report. If not, it would also help if you could attach an RVI packet trace for the time where you reproduced the problem.

Please post your bug number, just for the record.

Share and Enjoy

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

Thank you for your response. I did file a bug report: https://feedbackassistant.apple.com/feedback/9374056

I will try to add the additional info you mentioned.

I also filed a bug before finding this post. FB9631338. We have been able to work around this by using cordova-plugin-advanced-websocket which uses socketrocket.

Was somebody able to work around this without socketrocket?

is there still any way this will be fixed for the ios release?

We suspect that this is fallout from a change in WKWebView where it switched from a custom WebSocket implementation to the one in NSURLSession. However, we’re not 100% sure. If you can reproduce this with a server that’s available on the public Internet, please file a bug about this and attach a tiny test project that demonstrates the issue. Or, if you’ve already filed a bug (thanks!) attach it to that bug.

Was somebody able to work around this without socketrocket?

If you use the WebSocket support in NSURLSession, does it suffer from the same problem?

Likewise, when happens if you use the WebSocket support in NWConnection?

These points are relevant because a) the lower down the stack you go the more we can focus your bug report, and b) they might lead to a workaround.

Share and Enjoy

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

Got it, thank you for your response.

It will take a few days for us to produce a minimal test project. That said, I did find out today that while the connection consistently doesn't work initially, it does consistently succeed after 90 seconds of the app being in the foreground. Maybe that helps investigating the issue?

It will take a few days for us to produce a minimal test project.

Thanks for taking the time to do that.

I did find out today that while the connection consistently doesn't work initially, it does consistently succeed after 90 seconds of the app being in the foreground.

Weird.

Maybe that helps investigating the issue?

Perhaps. When you discover potentially useful info like this, please add it to your bug report so that the folks investigating this see it.

Share and Enjoy

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

Just one more observation: I found that the issue seems to be depending on the size of the message. In my example project a 125 byte message can be sent but a 126 byte message cannot....

We faced error WebSocket connection to 'wss:****' failed: The operation couldn’t be completed. (kNWErrorDomainPOSIX error 100 - Protocol error) with big websocket messages on iOS15 (production, not beta) if server responds with "Sec-WebSocket-Extensions: permessage-deflate; server_no_context_takeover; client_no_context_takeover", if there are no such headers or if message very small then all works fine. Maybe there is a bug with websockets compression in WKWebView

This error is caused by NSURLSession’s inability to process split messages normally. As long as the received WebSocket Message Frame is Fin=0, an error will occur. Our team adjusted the WebSocket Server configuration in the production environment to solve this problem.

Hi nansen_su ~ I have same problem aboult NSURLSession and WebSocket Message Frame Fin=0 error ,have any web page reference let me to know how to adjusted the WebSocket Server configuration,thx

Hi, i am facing a similar Problem since iOS 15. In my case, it is a JavaScript client trying to communicate with Wowza Streaming Engine. The connection fails as soon the client tries to send some data.

Disabling "NSURLSession WebSocket" resolves the issue.

While my project is not available to the public, I found a page (which I am not related to), where the issue can be reproduced

https://libwebsockets.org/testserver/ (click on the "send junk" button)

Is apple planning to disable it in the next release?

Apple generally doesn’t discuss its future plans.

For all those reading along at home…

If this problem is causing you grief I encourage you to file a bug about it. If you can attach a tiny test project that reproduces the issue with a site that’s available on the public Internet, that’d be fab. If not, see my post above for the next best thing.

Please post your bug number, just for the record.

Share and Enjoy

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

Faced the same issues with iOS15 and private Wowza based project. According Wowza docs their WebSocket lib doesn't support packet fragmentation feature at all: https://www.wowza.com/resources/serverapi/com/wowza/wms/websocket/model/IWebSocketSession.html#getPacketFragmentationSize--

Same issue here with Safari on iOS 15 and also MacOS Monterey beta7. On MacOS Chrome works fine.

It is a websocket server based on Espressif ESP32 hardware with a simple webserver built on the lib: https://github.com/me-no-dev/ESPAsyncWebServer

Setting safari =>Advanced=>Experimental Features=>NSURLSession WebSocket to off solves the issue. I can connect one of the devices for testing to the public internet if that helps.

So Safari completely broke a ton of people's code and then refuses to even acknowledge the problem. Typical.

Hi we have same problem, did anyone solve this issue. how can disable NSURLSession on WKWebview ?

I am having this issue but only with 14.7.1 and 14.8. 15 actually works for me. Very simple websocket application on virtual hosted server (dreamhost) with SSL from letsencrypt. frustrating. exact same web app works fine on other versions of ios.

Safari … refuses to even acknowledge the problem.

What sort of acknowledgement are you looking for?

Safari is an app and so it doesn’t acknowledge things. I’m a person, and I do say things that folks interpret as being from Apple. I’ve made a number of posts on this thread, including this, this, this, and this. I think that’s pretty good coverage of this issue, especially when combined with the helpful info posted by other third-party developers.

My last post on this thread also included a call to action on your part.

If you have a specific question that remain unanswered, please post them here and I’ll do what I can. And I’d appreciate that question coming with a bug number.

Share and Enjoy

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

I'm facing a similar issue, where the server in my cordova app (server based on https://github.com/zwopple/PocketSocket) actually crashes if a iOS 15 client (iOS 15.0.2 in this particular case) tries to send data.

The error happens here:

// inflate if necessary
if(_pmdEnabled && !frame->control && (frame->rsv1 || _initialFrame->rsv1)) {

(Line 682 of PSWebSocketDriver.m of said library)

The error message marks this as the source of the error: _initialFrame

And this is the error: Thread 30: EXC_BAD_ACCESS (code=1, address=0x9)

I've tested sending messages to the public websocket server test page https://libwebsockets.org/testserver/, mentioned by @DirtyHerri. The connection is established, but if I send data using the "Send Junk" button, the connection is closed, so I guess something similar is happening there. Toggling NSURLSession WebSocket in Safaris experimental features section doesn't have any effect for me.

This issue is still not solved in IOS 15.2

It's easy IOS15 NSURLSession WebSocket is default On, server receive multiple frame. change server code to solve sticking and unpacking problems

Our application is H5 / cordova / wkwebview, we are also facing exactly the same problem, the test to manually close NSURLSession, it is effective in safari browser.

Does anyone know the exact solution? Or know how to close NSURLSession in wkwebview?

We have evaluated to switch to cordova-plugin-advanced-websocket, but the cost is a bit high, and we cannot make this decision yet.

=== delete repeat post ===

Is there any word on whether this will be addressed at some point? This is a big problem for our business and we don't really see a way to work around this (we tried different server side websocket configurations, but so far no luck).

This used to work in iOS 14. Is there any way to configure the WKWebView to use the legacy code for now? Should we pull the app from the App Store for now? Is there any recommendation by Apple on how to handle this?

iOS 15 WKWebView websocket behaviour
 
 
Q