Skip to content

Socket disconnect not fired when device loses network #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
phansen-nd opened this issue Jun 14, 2022 · 9 comments
Open

Socket disconnect not fired when device loses network #1415

phansen-nd opened this issue Jun 14, 2022 · 9 comments

Comments

@phansen-nd
Copy link

phansen-nd commented Jun 14, 2022

Version 16.0.0

Expected behavior
A connected socket will fire the disconnect event when a device loses network. Or fire any event, like statusChanged or reconnect.

Actual behavior
No disconnect event is emitted until the ping timeout 60 seconds later.

I've tried the following code to get any indication that the socket is no longer connected:

socket.onAny { event in
     print("Got event: \(event.event), with items: \(event.items)")
}
socket.connect()

but no event fires when the device loses network until 60 seconds later.

For what it's worth, the Java SocketIO client is connected to the same server and receives a disconnect event immediately upon losing network, so it does not seem to be anything to do with the server configuration.

@msobiepanek-uz
Copy link

Hey! Have you setup all parameters related to reconnection? Eg:

    let config = [
      .log(true),
      .forceWebsockets(true),
      .reconnects(true),
      .reconnectAttempts(5),
      .reconnectWait(1),
      .reconnectWaitMax(10)
    ] as SocketIOClientConfiguration
        
    socketManager = SocketManager.init(socketURL: url, config: config)

It's working properly with above config in my case, so I get several reconnect events and then disconnect.

@miguel-arrf
Copy link

I'm dealing with the same issue. Any update @phansen-nd ?

@phansen-nd
Copy link
Author

@miguel-arrf no we ended up using a different network handler because this didn't work.

@miguel-arrf
Copy link

@miguel-arrf no we ended up using a different network handler because this didn't work.

Oh... @phansen-nd . Thank you anyway!

@WestFlow127
Copy link

WestFlow127 commented Nov 3, 2023

This seems to still be an issue... network disconnects causing socket failure should emit a disconnect.

*Edit: When a user loses network connection completely, or switches from Wifi to LTE, it takes about 50-60 seconds for the .error event to be emitted from the SocketManager.defaultSocket. In case of switching network type, it will reconnect using the new network type, but at that 50-60 second delay. Can this be changed to be quicker? ie 2 second delay?

@WestFlow127
Copy link

@nuclearace can we get some input on this?

@WestFlow127
Copy link

@miguel-arrf no we ended up using a different network handler because this didn't work.

Did you use Apple's Network framework to detect changes in network and force reconnect? @miguel-arrf

@neobie
Copy link

neobie commented May 22, 2024

It used to walk back in 2021. Not sure why now is not working when i am debugging.

@deanylev
Copy link

deanylev commented Mar 4, 2025

This is still an issue unfortunately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants