azure-signalr icon indicating copy to clipboard operation
azure-signalr copied to clipboard

Connection dropped - kNWErrorDomainPOSIX error 53 (error 1006) - when switching to another app on iOS 15.1.1

Open wzoet opened this issue 3 years ago • 11 comments

Describe the bug

We are using Azure SignalR to connect to a web service we are running. This system is running for several years now without any issues. Recently we have begun to see 1006 disconnection errors on iOS. The error occurs when a user uses our software on an iPhone. Our software interacts with a 3rd party that sends an authorization request (push message) to another app on the same phone. To authorize our request, the user has to acknowledge the request within the app of the 3rd party. When the user does not switch back instantly to safari, the connection gets dropped with error 1006.

Searching for the error makes me think it has something to do with background network traffic being forcibly closed when switching to another app.

We are looking if auto reconnect can help us fix this issue. Our connection settings are set to ping every 30 seconds and normally we don't experience any timeouts or connection drops.

To Reproduce

Enable debug mode within the iPhone and open a random SignalR powered website. Open the web debug window in OSX to see console messages on the Mac. Briefly switch to another random app for 1-2 seconds. Go back to safari. The console will show error 1006.

Exceptions (if any)

WebSocket connection to <> failed: The operation couldn’t be completed. (kNWErrorDomainPOSIX error 53 - Software caused connection abort) Error: Connection disconnected with error 'Error: WebSocket closed with status code: 1006 ().'.

Further technical details

The libraries we are currently using are:

  • Microsoft.AspNetCore.SignalR v1.13.0
  • @microsoft.signalr ^5.0.11

Thanks for thinking along.

wzoet avatar Jan 13 '22 19:01 wzoet

It seams that this issue is caused by changes in iOS as also mentioned in https://github.com/react-native-webview/react-native-webview/issues/2281. The solution as specified by nverwer to disable NSURLSession makes the issue disappear.

  1. Open the Settings app
  2. Scroll down and tap on “Safari”
  3. Scroll down to the bottom and tap on “Advanced”
  4. Tap on “Experimental Features” at the bottom
  5. Scroll down until you see “NSURLSession WebSocket”
  6. Disable “NSURLSession WebSocket”

Of course this is only a workaround and not the real solution of this issue. I will leave this issue open as I don't know whether Azure signalr library should be adapted to the new implementation in iOS15.

wzoet avatar Jan 14 '22 10:01 wzoet

Looks like the WebSocket connection is closed by iOS. Since it is the SignalR client, I don't think there is much that Azure SignalR SDK can help with.

Can "re-start the connection" once 1006 is detected workaround this issue? For example, with such approach: https://github.com/Azure/azure-signalr/blob/e6c3768de36d0c0edd260d867bb15916868ef3b4/samples/ChatSample/ChatSample.Net50/wwwroot/index.html#L168-L174

vicancy avatar Jan 25 '22 05:01 vicancy

i've had luck keeping some background task running in the webview like an interval or request animation frame while the webview or browser is backgrounded like:

setInterval(() => {
	// keeps websocket open while app / webpage is backgrounded
	console.log('keep alive');
}, 2000);

or

function repeatOften() {
	requestAnimationFrame(repeatOften);
}
requestAnimationFrame(repeatOften);

spencercap avatar Mar 30 '22 20:03 spencercap

Any update on this issue? @wzoet @spencercap @spencercap @mattetti

deepak-vanco avatar Jul 01 '22 14:07 deepak-vanco

Unfortunately not. OSX and iOS have implemented this as experimental feature. And no workaround seems to be available. We advise turning this feature off as a workaround in our user manual.

wzoet avatar Jul 01 '22 19:07 wzoet

this is definitely a spotty flow on mobile. especially on crowded LTE networks as well as device to device on firmware versions...

alas, we've had some luck keeping the thread alive by playing audio in the background (even a completely silent audio track) as demo'd in our algorand library here: https://github.com/thencc/algonautjs/blob/65142a39bff51b49a2ce4924b8ec585dd3284f04/src/index.ts#L2301-L2332

spencercap avatar Jul 06 '22 15:07 spencercap

this still an issue? @wzoet @spencercap @spencercap @mattetti

I'm developing a web view app that requires sockets, and it was lovely to discover this error when I finally tested it on mobile... Has anyone found a solution?

SkylarkingMonkey avatar Oct 07 '22 02:10 SkylarkingMonkey

@SkylarkingMonkey it was such an issue we abandoned the approach and haven't tried again since.

spencercap avatar Oct 08 '22 01:10 spencercap

Issue is really bad :( We are using auth with SignalR and smart-id. Whenever user on iphone goes to the app to confirm the pin, connection is aborted and user is not going anywhere. Reconnect doesn't help since when it tries to reconnect it is already too late.

EvaldasMazeika avatar Sep 26 '23 08:09 EvaldasMazeika