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?

Post not yet marked as solved Up vote post of j4nnis Down vote post of j4nnis
26k views

Replies

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?

Post not yet marked as solved Up vote reply of mhub Down vote reply of mhub

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

  • It definitely is related to websocket compression, but that is not the whole story. We have a nodejs websocket server, serving wss connections.. with message compression turned on, our iOS 15 app will not connect (it tries to upgrade, but the connection is never successfully established). When I turn message compression off, the app will connect as usual... however, all is not well... it drops the connection after a short time with close code 1006 (seems to be on the order of a minute or so)... the server is not initiating this closure.. and immediately afterwards, it looks like the client is trying to connect again..

Add a Comment

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.

  • Can you please describe how did you adjust your WebSocket Server configuration in the production?

  • I am joining to this one. Could you share some details if they are known, please?

  • Please provide more insight on how to adjust our WebSocket configuration and what parameters need to be changed.

Add a Comment

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

  • My problem is :if I use IOS 15 iphone send message to WebSocket server ,server receive multiple frame ,but in IOS 14.X only receive one frame. For example a message 「 I have an apple」, in IOS 15 my WebSocket server will receive 「 I have」+「an apple」,must receive twice or more,but in IOS 14.X my WebSocket server receive 「 I have an apple」 just receive once

  • by the way,I found in my IOS 15 setting 「safari =>Advanced=>Experimental Features=>NSURLSession WebSocket 」is default On, in IOS 14.X is default Off,I'm not sure it has an impact.

Add a Comment

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)

  • DId you managed to disable it through wkwebview? My app is breaking because of this. Is apple planning to disable it in the next release?

  • Faced the same issue with iOS15 and private project on top of Wowza server. According Wowza docs packet fragmentation is not supported by used lib: https://www.wowza.com/resources/serverapi/com/wowza/wms/websocket/model/IWebSocketSession.html#getPacketFragmentationSize--

  • How do you disable NSURLSession Websocket?

Add a Comment

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.

  • Hey ArjemH,

    I have exact the same usecase and the same problem. Thanks a lot for the fix in the iOS settings. Can you hit me up, if you found a real solution for the problem with the ESP32?

    Thank you!

Add a Comment