News for hackers. Stuff that matters.
Re:Callback Hell (2016) by simplify on Wednesday February 15, 2017 @03:42PM (#13655191)
This is correct. Race conditions are still the most common vulnerability in web applications.

Take a classic example: a one-time use coupon. Without some kind of locking, two simultaneous requests would be able to use the same coupon successfully. Roughly:

  0.0s - [1] Client 1: Apply coupon
  0.0s - [2] Client 2: Apply coupon
  0.1s - [1] Server to database: Is coupon marked as used?
  0.1s - [2] Server to database: Is coupon marked as used?
  0.2s - [1] Database to server: Nope! All good.
  0.2s - [2] Database to server: Nope! All good.*
* Since the question was asked for both requests at the same time, the answer was "Not used" in both cases.

  0.3s - [1] Server to database: Update coupon as used.
  0.3s - [2] Server to database: Update coupon as used.*

         * Coupon has been used twice :(
Node's async model is not going to help you here. You will need something more, such as a mutex.
Re:Callback Hell (2016) by Chyzwar on Wednesday February 15, 2017 @04:55PM (#13655707)
Nope, your ACID database will ensure that two writes in the same time for the same record will not happen. You don't even need to ask database if coupon is used. You just try to use coupon, if already used return message to user.

Node give you freedom from Thread Hell. You enjoy similar performance without locks, threads, synchronisation. Race conditions happen but mostly with cache invalidation where you can have limited consistency guarantees.

Re:Callback Hell (2016) by paulddraper on Wednesday February 15, 2017 @11:03PM (#13657676)
Right; you need to put your lock in the database, encoded as an index.
Re:Callback Hell (2016) by simplify on Thursday February 16, 2017 @01:28AM (#13658116)
The problem isn't "two writes at the same time", it's the server thinking everything's OK for two separate users.

If can model your database differently for this rudimentary example, then good for you – you're thinking about race conditions. Many web programmers do not think about them at all, and race conditions are usually not trivial to fix.

Re:Callback Hell (2016) by Can_Not on Saturday February 18, 2017 @02:43PM (#13676320)
> Use ACID compliant Database or not

How is that specific to only NodeJs?

Re:Callback Hell (2016) by novaleaf on Thursday February 16, 2017 @12:52PM (#13661991)
agree. the coupon problem would be best fixed with atomic database transactions.

in fact, an entirely synchronous, 1-user-at-a-time server wouldn't fix this, if there were two or more servers. and honestly, who would design any system that only supports 1 concurrent user?

Re:Callback Hell (2016) by drewgross on Thursday February 16, 2017 @12:47AM (#13657983)
Calling race conditions the "most common" vulnerability seems like some pretty extreme hyperbole. What about SQL injection or XSS?
Re:Callback Hell (2016) by simplify on Thursday February 16, 2017 @01:22AM (#13658099)
You're right, I meant to say the most commonly unaware vulnerability.
Re:Callback Hell (2016) by z3t4 on Thursday February 16, 2017 @02:54AM (#13658343)
This is a problem in the database layer, not NodeJS!