Skip to content
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

Starscream hangs when trying to connect with multiple sockets #153

Closed
rvera opened this issue Dec 31, 2015 · 2 comments
Closed

Starscream hangs when trying to connect with multiple sockets #153

rvera opened this issue Dec 31, 2015 · 2 comments

Comments

@rvera
Copy link

rvera commented Dec 31, 2015

I need to create multiple simultaneous sockets and starscream consistently hangs if I try to create over 64 of them.

So this code fails, the connected callback never gets triggered.

# Class var
var websockets = [WebSocket]()

# In a method
for index in 1...64 {
    if let newWebSocket = WebSocket(url: YOUR_WS_URL) as WebSocket? {
        newWebSocket.onConnect = {
            print("\(index) Connected")
        }
        newWebSocket.onDisconnect = { (error) -> Void in
            print("\(index) Discconnected")
        }
        print("\(index) Connecting")
        newWebSocket.connect()
        self.websockets.append(newWebSocket)
    }
}

Seems to be related to this issue http://stackoverflow.com/questions/15150308/workaround-on-the-threads-limit-in-grand-central-dispatch and the way starscream always dispatches on the background https://github.com/daltoniam/Starscream/blob/master/WebSocket.swift#L144

Maybe move this into a static private operation queue?

@acmacalister
Copy link
Collaborator

This is similar to a suggestion opened up on Jetfire (Objective-C equivalent)

acmacalister/jetfire#15

We have looked into a singleton thread and using a stream based APIs to fix this issue, but it requires a rather large refactor we haven't had time to finish yet. If you would like to take a stab at it, PR is welcomed.

@daltoniam
Copy link
Owner

The 1.1.0 release should resolve this. Let us know if you have any issues.

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

3 participants