title: node-mysql transaction is not rolling back after unique key violation
body: <p>I'm testing node-mysql transactions in my application by performing an INSERT that will violate a UNIQUE key constraint, after first performing an UPDATE. While the INSERT fails, I find that the initial UPDATE is succeeding, despite the transaction with ROLLBACK's. A MySQL UPDATE doesn't perform an implicit commit, so I'm not sure what exactly is going on here.</p>
  
  <pre><code>pool.getConnection(function (err, connection) {
  
      connection.beginTransaction(function (err) {
          if (err) {
              console.log(" --- error 1: " + JSON.stringify(err));
          }
  
          console.log(" --- A");
  
          connection.query('update course_person set rescheduled_date = CURDATE() where idperson = ? and rescheduled_date is null', [idperson], function (err, rows, fields) {
  
              if (err) {
                  connection.rollback(function () {
                      console.log(" --- error 2: " + JSON.stringify(err));
                  });
  
                  console.log(" --- B");
  
              }
  
              console.log(" --- C");
  
          });
  
          connection.query('insert into course_person (idcourse, idperson) VALUES (?, ?)', [newidcourse, idperson], function (err, rows, fields) {
  
              if (err) {
                  connection.rollback(function () {
                      console.log(" --- error 3: " + JSON.stringify(err));
                  });
  
                  console.log(" --- D");
  
              }
  
              console.log(" --- E");
  
          });
  
          connection.commit(function (err) {
              if (err) {
                  connection.rollback(function () {
                      console.log(" --- error 4: " + JSON.stringify(err));
                  });
  
                  console.log(" --- F");
  
              }
  
              console.log(" --- G");
  
              req.flash('success', 'Person was updated successfully.');
              res.redirect('/person/' + idperson);
  
              connection.release();
          });
  
      });
  
  });
  </code></pre>
  
  <p>I'm getting the following output sequence:</p>
  
  <pre><code> --- A
   --- C
   --- D
   --- E
   --- G
   --- error 3: {"code":"ER_DUP_ENTRY","errno":1062,"sqlState":"23000","index":0}
  </code></pre>
  
  <p>And Here's my proof :)</p>
  
  <p><a href="https://i.stack.imgur.com/6mBml.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6mBml.png" alt="enter image description here"></a></p>