mardi 5 mai 2015

"stacking" mysql queries? multiple queries in millisecs each browser-refresh

I'm pretty new to socket.io and nodejs and at first I didn't even notice where the problem comes from until I 'console.log'ed nearly every function now.
I found out that refreshing the browser will "stack" up the console.log data and I assume also the mysql-queries I'm sending.

It's about a penny-auction website I'm building and I want to update every auction if there's a new bid or in another specific case. Every time this happens the auction-duration-time also increases. The client-side-javascript file keeps the connection to socket.io and updates the countdown timer when the price changes and stores the "new duration" that is left in seconds in an array that counts down to not constantly sending queries to the mysql database every second.

The main problem is: If the timer drops to 0, the client-side-file visually changes an auction to a "SOLD"-state, even if that's not the case server-side.
If you refresh your browser again, it's still counting down then.

If I restart my node server it works fine again. But I can't even image what will happen if multiple users refresh the website and will see the same not-intended behaviour. I also don't know how these "mulitple stacking" queries cause the problem to show the countdown counting to zero and doesn't reset the timer like it should be.

I've documented the bug in a video to show it to you more clearly: http://ift.tt/1EVRGqx

However there must be something wrong in my server.js-code, I guess. I can't figure out where exactly. I really hope anyone can help me somehow.

PS: The code structure comes from a nodejs-socket-io-mysql-tutorial: http://ift.tt/1lAN24d

Aucun commentaire:

Enregistrer un commentaire