-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsettled promises shouldn't be stored. #1181
Comments
👍 I often had some uneasy feelings about this when seeing this code parts but couldn't put it into words what would have bothered me since I am not so firm with promises, thanks for this write-up. Would say that we should change here soon, we also have this pattern in some parts of the client. |
In both cases we could make the constructor of these classes |
Yeah, I really like that pattern. Even more than the |
I am working on a PR to resolve this in Below is a working list of other places I've found with stored promises:
|
I'm digging through the synchronizer code this morning and saw this |
Closed by #1811 |
When upgrading to v5 I discovered that there are multiple promises being stored, which is pretty dangerous and should be avoided. I've seen these two, but there's probably more:
mclInitPromise
in the VMinitPromise
in the BlockchainThe reason this is dangerous is that they may be rejected before they get to be handled. In the case of
Blockchain
, there's some code that I believe tries to avoid it, but throwing in thecatch
of a promise just leads to a new one that's also rejected.This is particularly problematic in Node 15+, as unhandled promise rejections now kill the process, even if the promise was stored. For example, this leads to a crash:
How can these be done instead?
mclInitPromise
: I'd move its initialization into the opcode/precompile handlers that need them. Those are already async.Blockchain
: Same as the VM, have aninit
method be called and await before every operation.The text was updated successfully, but these errors were encountered: