node.js - Possibilty of writing to a wrong object with callback -
i'm using nodejs socket.io server handling realtime things. there event in socket.io authenticating user. code looks follows:
var io = require('socket.io').listen(8080) io.on('connection', function(socket) { socket.on('auth', function(id) { conn.query('select id u id = ?', id, function(e, result) { socket.id = result[0].id }) }) )} my worries line here:
socket.id = result[0].id this in callback. when db executed query. question is: there possibility there can wrong assignment lot of of connections @ same time? seems happenend , data got assigned wrong socket object. there better methods reliably things this?
the socket object has built-in field id. http://socket.io/docs/server-api/#
strong textsocket#id:string
a unique identifier socket session, comes underlying client.
your code trying assign different value built-in field, seems bad idea. should try rename "your" id field else authid or userid avoid conflict.
Comments
Post a Comment