socketio / socket.io-client-swift

Other
5.21k stars 841 forks source link

Connecting to the server with nginx load balancer sends socket.io iOS client into reconnection spiral #1422

Open Ariandr opened 2 years ago

Ariandr commented 2 years ago

I use socket.io version v.16.0.1, iOS 15.5.

My configuration is this: image

Then I just call this method once: manager.defaultSocket.connect()

The problem: Connecting to the server with nginx load balancer sends socket.io iOS client into reconnection spiral. According to the logs, the engine is being constantly recreated without stopping.

Calling this doesn't stop the manager from being disposed and logs show that it still tries to reconnect.

func closeConnection() {
    socket.removeAllHandlers()
    socket.disconnect()
    manager.disconnect()
}

Essentially, you cannot stop this process, and eventually it brings the server down because of spamming an enormous number of connection requests.

Expected behavior: Socket client should respect reconnection intervals and don't fall into spiral of recreating engines and sending attempts to reconnect dozens of times in a couple of seconds.

Logs example: 2022-08-04_13-35

These logs repeat forever, so essentially it recreates the engine and starts it again.

Ariandr commented 2 years ago

Hi @nuclearace For me it seems like a serious bug in connection logic

nuclearace commented 2 years ago

@Ariandr Thanks for reporting this. Does this reconnect spiral happen every time something happens to the client that causes it to reconnect? Or does it try to reconnect after you try and call close on the socket?

nuclearace commented 2 years ago

Also, does this only happen with nginx in front on the server? That might be more tricky for me to reproduce.

Ariandr commented 2 years ago

Hi @nuclearace It happens regardless of trying to close the connection or no.

You just execute connect() method and it goes into the spiral. Closing just doesn't stop it.

Ariandr commented 2 years ago

Also, does this only happen with nginx in front on the server? That might be more tricky for me to reproduce.

Maybe it can be any load balancer that doesn't let you socket connection to remain open. But in my case it was nginx.