v0.5.0 errors on concurrent transactions
cvlmtg opened this issue · comments
I've this (pseudo) code in my model which is called by many concurrent requests to my server:
@filter({ code: json.code }).isEmpty().chain (isEmpty) =>
unless isEmpty
callback "meaningful error message"
return
json = sanitizeData json
create = (db, done) =>
@save(json).classic (err, result) ->
return done err if err
async.each someOtherDataToSave, iterator, done
return
@db.transaction({ isolated: true }, create).classic callback
every time I run the unit test, the first transaction is ok, while the second one seems to end too early, so I've an error because my code tries to call a method on null instead of the saved model. with my fork this doesn't happen.
return xxx.getSomething(lang, function(attrs) {
^
TypeError: Cannot call method 'getSomething' of null
btw looking at the mysql log I've found a (probable) error.
349 Query SELECT 1 FROM `xxx` WHERE (`code` = 'e2317300') LIMIT 1
350 Query SELECT 1 FROM `xxx` WHERE (`code` = 'efcbdcbd') LIMIT 1
351 Query SELECT 1 FROM `xxx` WHERE (`code` = '754e5389') LIMIT 1
352 Query SELECT 1 FROM `xxx` WHERE (`code` = 'bb680f88') LIMIT 1
353 Query SELECT 1 FROM `xxx` WHERE (`code` = '2c71a0d6') LIMIT 1
354 Query BEGIN
354 Query INSERT INTO `xxx` (`createdAt`, `updatedAt`, `code`, etc...
354 Query INSERT INTO `yyy` (`createdAt`, `updatedAt`, etc...
354 Query COMMIT
348 Query BEGIN
355 Query SELECT * FROM `zzz` WHERE...
349 Query SELECT * FROM `yyy` WHERE...
348 Query INSERT INTO `xxx` (`createdAt`, `updatedAt`, `code`, etc...
348 Query SELECT 1 FROM `xxx` WHERE (`code` = 'e85854ec') LIMIT 1
logs ends here ^
As you can see the last select is run inside my transaction (connection id 348), and I suppose this is wrong. this happens with my fork too, so my patch was incomplete too :) but I suppose I didn't catch it because my code ran without errors. Anyway, this should not be the cause of my errors with v0.5.0, but it's still something else that might be needed to look upon.
If I'll be able to understand what goes wrong with v0.5.0 I'll add my info here.
I think I solved the problem, I'm going to make a pull request as soon as possible.
I'm obviously not sure 100% my patch is the correct one, so your review will be needed :)
I found a problem with savepoints, so my patch needs more work
it was just a typo. the doc says the option is "isolated", but in the code there was "isolate". I decided to follow the doc.