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

fix timing issues with middleware #2948

Merged
merged 1 commit into from
May 22, 2017

Conversation

darrachequesne
Copy link
Member

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behaviour

Using a middleware could previously lead to a connecting client
receiving a connect event from the server before the server triggers
its own connect event.

New behaviour

Other information (e.g. related issues)

Fixes #2935.

Using a middleware could previously lead to a connecting client
receiving a connect event from the server before the server triggers
its own connect event.
@AVVS
Copy link

AVVS commented Jun 3, 2017

this created another problem - if .attach/listen was not called before .use it crashes node process due to delete this.server.eio.initialPacket; as this.server.eio is undefined before that call

@dolphinlin
Copy link

the commit let SWIFT SDK can't run!!!!!!!!!!!!!!
SWIFT connect to namespace that use a middleware, there is fail!!!

i delete the code, it works!!!!

// delete this.server.eio.initialPacket;

socket.io client

func testLocalhost() {
        let expectation : XCTestExpectation = self.expectation(description: "Wait for socket call back")
        
        let accessToken = "qqq"
        
        let socket = SocketIOClient(socketURL: URL(string:"http://localhost:3000")!, config: [
            .log(true),
            .nsp("/location"),
            .forceWebsockets(true),
            .connectParams(["x-access-token": accessToken]),
            .secure(false)
            ])
        
        socket.on("connect") { (data:[Any], emitter:SocketAckEmitter) in
            XCGLogger.info("We got connect.")
            expectation.fulfill()
        }
        socket.connect()
        
        self.waitForExpectations(timeout: waitForTimeout + 5) { (error:Error?) in
            if error != nil {
                XCGLogger.error("Waiting time out")
            }
        }

    }

socket.io server

var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var locationIO = io.of('/location')

const authCheck = (client, next) => {
	console.log('auth check')
    console.log('Access Token:' + client.handshake.query['x-access-token'])
    next()
}

io.on('connection', () => {
	console.log('main io connection!')
})

locationIO.use(authCheck)

locationIO.on('connection', function(){ 
	console.log('client connect success!')
});


server.listen(3000);

Nibbler999 pushed a commit to Nibbler999/socket.io that referenced this pull request Aug 22, 2017
dzad pushed a commit to dzad/socket.io that referenced this pull request May 29, 2023
Using a middleware could previously lead to a connecting client
receiving a connect event from the server before the server triggers
its own connect event.
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

Successfully merging this pull request may close these issues.

Server lost the message which is sent in client reconnect event handler
3 participants