Possibilty of writing to a wrong object with callback

I'm using a NodeJS Socket.IO server for handling realtime things. There is also an event in Socket.IO for authenticating a user. The code looks as follows:

var io = require('socket.io').listen(8080)

io.on('connection', function(socket) {

    socket.on('auth', function(id) {

        conn.query('SELECT id FROM u WHERE id = ?', id, function(e, result) {

            socket.id = result[0].id

        })

    })

)}

My worries are about this line here:

socket.id = result[0].id

This is in a callback. When the DB executed the query. So my question is: Is there a possibility that there can be wrong assignment with a lot of of connections at the same time? Seems that this happenend already and data got assigned to the wrong socket object. Are there better methods for reliably do things like this?

The Socket object has a built-in field id. From http://socket.io/docs/server-api/#

strong textSocket#id:String

A unique identifier for the socket session, that comes from the underlying Client.

Your code is trying to assign a different value to this built-in field, which seems like a bad idea. You should try to rename "your" id field to something else like authId or userId to avoid this conflict.