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

Create and Connect many sockets crashes/hangs #232

Closed
lightsprint09 opened this issue Nov 10, 2015 · 13 comments
Closed

Create and Connect many sockets crashes/hangs #232

lightsprint09 opened this issue Nov 10, 2015 · 13 comments

Comments

@lightsprint09
Copy link
Contributor

Running the following test code hangs after connecting to a some Socket clients and all other clients time out. I think this isn't normal behavior.

func testMasstivConnect() {
      weak var expection = expectationWithDescription("massiv")
        var list = Array<SocketIOClient>()
        let count = 90
        for _ in (0..<count) {
            let newSocket = SocketIOClient(socketURL: "http://localhost:6979")
            openConnection(newSocket) {
                list.append(newSocket)
                print(list.count)
                if list.count == count {

                    expection?.fulfill()
                }
            }
        }
        waitForExpectationsWithTimeout(30.0, handler: nil)
    }
func openConnection(socket: SocketIOClient, isConnectedCallback:()->()) {
        if socket.status == .Connected {
            isConnectedCallback()
        }
        socket.on("connect") {data, ack in
            dispatch_async(dispatch_get_main_queue(), {
                XCTAssertEqual(socket.status, SocketIOClientStatus.Connected)
                XCTAssertFalse(socket.secure)
                isConnectedCallback()
            })

        }
        socket.connect(timeoutAfter: 29, withTimeoutHandler: {
            print("Did Timout connect")
        })
    }
@nuclearace
Copy link
Member

I would think that would be some kind of problem with NSURLSession or something along those lines. Have you tried testing this with forced WebSocket?

@lightsprint09
Copy link
Contributor Author

with let newSocket = SocketIOClient(socketURL: AbstractSocketTest.serverURL, options: [.ForceWebsockets(true)])
Every connection times out

@nuclearace
Copy link
Member

Is there a set number of connections that it opens before they subsequently start failing?

@lightsprint09
Copy link
Contributor Author

Without forced WebSockets about 20-60.

@nuclearace
Copy link
Member

20-60 is a pretty large range. Have you tried testing some sort of rate limiter? Also is there some sort of error message that happens?

@lightsprint09
Copy link
Contributor Author

ok 63 work, 64 doesn't

@nuclearace
Copy link
Member

What platform are you testing on?

@lightsprint09
Copy link
Contributor Author

Mac OS

@nuclearace
Copy link
Member

When I test this outside of XCTest it seems to work.

let NUM_SOCKETS = 90
var connects = 0
let sockets = [SocketIOClient](count: NUM_SOCKETS, repeatedValue: SocketIOClient(socketURL: "localhost:8080"))

for socket in sockets {
    socket.on("connect") {data, ack in
        connects++
    }
    socket.connect()
}

let waitTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1 * NSEC_PER_SEC))
dispatch_after(waitTime, dispatch_get_main_queue()) {
    assert(connects == NUM_SOCKETS, "Did not connect all sockets: \(connects)")
}

@nuclearace
Copy link
Member

Anymore on this?

@nuclearace
Copy link
Member

@lightsprint09 Anymore on this?

@lightsprint09
Copy link
Contributor Author

Did not have the time to investigate any further

@nuclearace
Copy link
Member

I think it has to do with daltoniam/Starscream#153 in which there's nothing really we can do.

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

No branches or pull requests

2 participants