Skip to content
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

Fix promise in accounts.signTransaction() throwing errors that cannot be caught #5080

Merged
merged 4 commits into from
Jul 15, 2022

Conversation

andreistefanwork
Copy link

@andreistefanwork andreistefanwork commented May 26, 2022

Description

Accounts.signTransaction() can generate a stray Promise under JS job queue, and there's no way for library users to catch any exceptions the stray promise throws, which can kill the entire Node.js process.

Fixes (#4724)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run dtslint with success and extended the tests and types if necessary.
  • I ran npm run test:cov and my test cases cover all the lines and branches of the added code.
  • I ran npm run build with success.
  • I have tested the built dist/web3.min.js in a browser.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.
  • I have updated the CHANGELOG.md file in the root folder.

@kai-alpha
Copy link

Unfortunately I'm not skilled in JS (esp. in raw Promises) enough to review your PR, but it's great you could write a unit test covering this case.

@andreistefanwork andreistefanwork changed the title fix Promise in Accounts.signTransaction() throwing errors that cannot… fix Promise in Accounts.signTransaction() throwing errors that cannot be caught Jun 4, 2022
@andreistefanwork
Copy link
Author

Hi @jdevcs! Can you guys review the PR and let me know if everything is alright?

@nazarhussain nazarhussain changed the title fix Promise in Accounts.signTransaction() throwing errors that cannot be caught Fix promise in accounts.signTransaction() throwing errors that cannot be caught Jun 22, 2022
@nazarhussain nazarhussain added 1.x 1.0 related issues Bug Addressing a bug Review Needed Maintainer(s) need to review labels Jun 22, 2022
@coveralls
Copy link

coveralls commented Jun 22, 2022

Pull Request Test Coverage Report for Build 2629557193

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • 287 unchanged lines in 8 files lost coverage.
  • Overall coverage increased (+2.4%) to 74.388%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/web3-eth-accounts/src/index.js 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
packages/web3-core-requestmanager/src/jsonrpc.js 1 70.0%
packages/web3-core-helpers/src/formatters.js 8 84.3%
packages/web3-eth-accounts/lib/index.js 20 85.46%
packages/web3-core-helpers/src/errors.js 29 1.56%
packages/web3-utils/src/soliditySha3.js 34 3.43%
packages/web3-utils/src/index.js 43 31.38%
packages/web3-utils/src/utils.js 45 10.67%
packages/web3-eth-accounts/src/index.js 107 23.67%
Totals Coverage Status
Change from base Build 2616214688: 2.4%
Covered Lines: 3265
Relevant Lines: 4139

💛 - Coveralls

Copy link
Contributor

@avkos avkos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. but need to check why tests fails

@andreistefanwork
Copy link
Author

Hi @avkos! Looking at the failed test, the promise: https://github.com/ChainSafe/web3.js/blob/9d5ce480d8f127e6868605fe684f9707a765e72b/test/e2e.contract.deploy.js#L112-L114

takes more that 2 seconds to resolve during e2e testing with Firefox browser. However, the same test using Chrome browser passes...

Also, this other very similar promise:
https://github.com/ChainSafe/web3.js/blob/9d5ce480d8f127e6868605fe684f9707a765e72b/test/e2e.contract.deploy.js#L97-L99

resolves both on Chrome and on Firefox..

I'm wondering, if we restart the tests, will it pass the second time? I'm really struggling to find a connection between the changes on the PR and the test that fails, without success

@kai-alpha
Copy link

Maybe you can rebase onto the latest HEAD and force-push to rerun the tests?

@andreistefanwork
Copy link
Author

Ok, so the second run was successful

Copy link
Contributor

@jdevcs jdevcs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreistefanwork This branch has conflicts that must be resolved

@jdevcs jdevcs added Future Release For future release. and removed Review Needed Maintainer(s) need to review labels Jul 6, 2022
@andreistefanwork
Copy link
Author

@jdevcs yes, some changelog.md conflicts. Solved them

@andreistefanwork
Copy link
Author

@jdevcs @nazarhussain Can this PR be merged & closed?

@jdevcs jdevcs changed the base branch from 1.x to junaid/promisefixsignTx July 15, 2022 15:03
@jdevcs jdevcs merged commit 42299f1 into web3:junaid/promisefixsignTx Jul 15, 2022
jdevcs added a commit that referenced this pull request Jul 15, 2022
@jdevcs
Copy link
Contributor

jdevcs commented Jul 15, 2022

Merged via #5252

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug Future Release For future release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants