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

Some exceptions thrown by web3-eth-account cannot be caught #4724

Open
1 task done
kai-alpha opened this issue Jan 21, 2022 · 11 comments
Open
1 task done

Some exceptions thrown by web3-eth-account cannot be caught #4724

kai-alpha opened this issue Jan 21, 2022 · 11 comments
Labels
1.x 1.0 related issues Bug Addressing a bug Investigate

Comments

@kai-alpha
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

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. A library shouldn't allow this to happen.

Expected Behavior

try { ... await account.signTransaction(tx) } catch (e) { ... } should be able to catch any exceptions thrown (conceptually) within signTransaction() method

Steps to Reproduce

Set tx.maxPriorityFeePerGas but not maxFeePerGas and send it to BSC (or any EVM-compatible blockchains without EIP-1559) to hit this throw at
https://github.com/ChainSafe/web3.js/blob/2b7c50a4cd27e5b21def779dd757cdacd2afd31a/packages/web3-eth-accounts/src/index.js#L433

Yes I know that doesn't make sense at all, but that's another story. A bug in our quick & dirty sandbox script led me to the issue.

Web3.js Version

1.7.0

Environment

No response

Anything Else?

_handleTxPricing() runs something like

return new Promise((resolve, reject) => {
  try {
    Promise.all([two async REST calls]).then(
      ...use the return value of the two REST calls...;
      resolve(suggested values for maxPriorityFeePerGas and maxFeePerGas))
  } catch (e) { reject(e) }
}

to asynchronously return the suggested values with resolve(), but I think the problem is that any exceptions thrown within the inner Promise.all() (and its then() chain) aren't propagated to reject() from the outer Promise.

Here is what I believe is a minimal repro: TS playground

JS isn't among my core expertise, I can't use JS Promise without async/await so this is all I can share.

Ping @spacesailor24 according to Git history

@kai-alpha kai-alpha added the Bug Addressing a bug label Jan 21, 2022
@nazarhussain
Copy link
Contributor

Thanks @kai-alpha for reporting the issue. We will look into to investigate further.

@spacesailor24 spacesailor24 added the 1.x 1.0 related issues label Jan 21, 2022
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Mar 23, 2022
@kai-alpha
Copy link
Author

wut, this is a real bug

@github-actions github-actions bot removed the Stale Has not received enough activity label Mar 24, 2022
@kristjanpeterson1
Copy link

Are there any updates on this? Seems like a very serious issue..

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label May 24, 2022
@kai-alpha
Copy link
Author

Hmm nobody is fixing this bug? Last attempt to get attention (I'll let the bot close it next time)

andreistefanwork added a commit to andreistefanwork/web3.js that referenced this issue May 26, 2022
… be caught web3#4724

Signed-off-by: Andrei Stefan <andrei.stefan.work@gmail.com>
andreistefanwork added a commit to andreistefanwork/web3.js that referenced this issue May 26, 2022
… be caught web3#4724

Signed-off-by: Andrei Stefan <andrei.stefan.work@gmail.com>
andreistefanwork added a commit to andreistefanwork/web3.js that referenced this issue May 26, 2022
… be caught web3#4724

Signed-off-by: Andrei Stefan <andrei.stefan.work@gmail.com>
@andreistefanwork
Copy link

Hi @kai-alpha! I was able to reproduce this issue as well. The problem seems to be indeed inside the inner Promise.all([promise1, promise2]) and its then() chain.

If an error occurs in either promise1, promise2 or inside then(...), it's not propagated to the outer Promise

This can be fixed using a catch(...) on the inner Promise.all()

I created the following PR, in which I also included a test to cover this change.

Can you double check everything looks alright?

@github-actions github-actions bot removed the Stale Has not received enough activity label May 27, 2022
andreistefanwork added a commit to andreistefanwork/web3.js that referenced this issue Jun 4, 2022
andreistefanwork added a commit to andreistefanwork/web3.js that referenced this issue Jun 16, 2022
nazarhussain added a commit to andreistefanwork/web3.js that referenced this issue Jun 22, 2022
andreistefanwork pushed a commit to andreistefanwork/web3.js that referenced this issue Jun 23, 2022
andreistefanwork added a commit to andreistefanwork/web3.js that referenced this issue Jun 23, 2022
andreistefanwork added a commit to andreistefanwork/web3.js that referenced this issue Jul 7, 2022
andreistefanwork added a commit to andreistefanwork/web3.js that referenced this issue Jul 7, 2022
andreistefanwork added a commit to andreistefanwork/web3.js that referenced this issue Jul 7, 2022
jdevcs added a commit that referenced this issue Jul 15, 2022
… be caught #4724 (#5080) (#5252)

Co-authored-by: Andrei Stefan <andrei.stefan.work@gmail.com>
@jdevcs jdevcs mentioned this issue Jul 15, 2022
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@TangMonk
Copy link

Still problem?

@jdevcs
Copy link
Contributor

jdevcs commented Oct 26, 2022

@TangMonk @kai-alpha are you still able to reproduce ?

@cocacola-lover
Copy link

It still happens on 4.6.0

(async function test() {
  try {
    await web3.eth.sendSignedTransaction("")
  } catch (e) {
    console.log(e)
  }
})()

@jdevcs jdevcs reopened this Apr 15, 2024
@github-actions github-actions bot removed the Stale Has not received enough activity label Apr 16, 2024
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 Investigate
Projects
None yet
Development

No branches or pull requests

8 participants