I have a piece of code that works 99 percent of the time, but occasionally fails and I'm trying to work out why.
It's a fantasy football game and in the draft users go in turns to pick players.
When you pick a player, two docs get updated: your team in the Teams collection and your league in the Leagues collection.
Your team gets updated with the player you picked and the league is updated to say that it's the next player's turn.
Before you pick a player, there's a check to see if it's currently your turn to pick.
The site is live and it's been working fine in general, but occasionally I run into the problem that this function is called twice and a player picks twice in a row.
One thing to note is that a timeout is set to pick for a player automatically if he hasn't picked within the allotted time. So I think the problem arises when you pick exactly when your time limit runs out and then two calls to the "pick player" function are made and each pick goes through because they each pass my check as to whose turn it is.
My question is how is this possible in Node.js? I thought everything runs in a single thread so the function couldn't be running twice at the same time.
Or is it something to do with mongodb and the database not being updated quickly enough? I'm using a MongoHQ elastic deployment.
I hope the question is clear. Any thoughts on how to fix the problem would be appreciated. I think I'll have to create a variable that keeps track of whose pick it is currently. At the moment this information is only stored in the Leagues collection.
If you want to check out the site, it's called DraftFantasyFootball.co.uk.
The thing is, the setTimeout for the automatic pick is from the server. The user picks using a meteor method.
I'll try post some code tonight. I really want to get this bug sorted quickly.
--
You received this message because you are subscribed to a topic in the Google Groups "meteor-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/meteor-talk/j1YF7JO5Rdo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to meteor-talk+unsubscribe@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to meteor-talk+unsubscribe@googlegroups.com.
Yes. Thank you. That's exactly what I was thinking tonight too