vendredi 17 avril 2015

how to handle concurrency issues in nodejs

I was preparing a chat application on nodejs using socket-io The problem is with concurrent callbacks, explaination is as follows: I keep in database socketId of related users, On disconnect event of socket-io I find the user based on its socket.id from mongodb, and do some db operations, remove the socket.id from subscriber socket list and update back the list(array in mongodb) in the same column. Now the problem is when there are concurrent requests.


All the callbacks finds the socketId Then all the callbacks create the list of socketids excluding itself(as event is disconnect) and then all updates back to db.


Problem in this approch is that Even though result is expected as blank column I end up with socketIds, only one is removed.


Hope was able to explain. Can anybody please let me know what I am doing wrong here?? This seems to be a very common problem what is the standard approach of solving same.??


Aucun commentaire:

Enregistrer un commentaire