-
Notifications
You must be signed in to change notification settings - Fork 89
Fix race condition due to mutated _getDBs/_putDBs #28
Conversation
Sorry, this was left aside a bit. Will have a look in the upcoming days (maybe next week). |
Hi @federicobond, trying to grab my head around this for review but I really have problems to understand why mutation and reassignment to self behaves differently. Will continue to dig into this but if you are around a note on this would be helpful. There also was a second PR https://github.com/ethereumjs/merkle-patricia-tree/pull/30/files after this one fixing the same issue as here, but also touching the Thanks! |
Anyhow, since you guys are discussing this for ages (just stumbled on the discussion on the bounty website and this appears to be a widely accepted patch, I will merge. A late explanation would be nice anyhow. Also if you see a chance to put this into some test like this from
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will approve, see discussion.
Just released this together with another bug fix as |
In case of mutation, an async iteration that started before may see the array in an inconsistent state. By reassigning we are letting the previous procedure keep a copy of the original list and only affect future requests.
I think it may be possible to write a test, but AFAIK depends on the specific event processing order and it's quite tricky to get right. I haven't attempted it though. |
Thank you @holgerd77! |
This fixes part of the issues described in trufflesuite/ganache#417.
The
asyncFirstSeries
function called insideTrie#getRaw
was iterating over an array that could be mutated by the checkpoint_enterCpMode
/_exitCpMode
functions, causing the familiarTypeError: Cannot read property 'get' of undefined
.I replaced the mutations with reassignments.
Note that the tests written in trufflesuite/ganache#41 still fail, now both with the same error:
TypeError: Cannot read property 'pop' of undefined
.