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

UnhandledPromiseRejectionWarning on sendSignedTransaction #2394

Closed
dystopiandev opened this issue Feb 19, 2019 · 9 comments
Closed

UnhandledPromiseRejectionWarning on sendSignedTransaction #2394

dystopiandev opened this issue Feb 19, 2019 · 9 comments

Comments

@dystopiandev
Copy link

dystopiandev commented Feb 19, 2019

Expected behavior

Errors should be trapped in callback error field or promise catch(e => {}).

Actual behavior

Not even a combination of try/catch and catch(e => {}) can trap this. It's never bubbled up.

Steps to reproduce the behavior

I haven't been able to figure out a precise way to reproduce this, except calling web3.eth.sendSignedTransaction leads here sometimes.

Error Logs

(node:29195) UnhandledPromiseRejectionWarning: Error: Node error: {"code":-32042,"message":"Bad response on request: [ TransactionIndex ]. Error cause was EmptyResponse, (majority count: 55 / total: 55)"}
    at Function.validate (/home/***/node_modules/web3-providers/dist/web3-providers.cjs.js:349:18)
    at /home/***/node_modules/web3-providers/dist/web3-providers.cjs.js:692:57
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:29195) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:29195) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Versions

Node: 10.14.2
NPM: 6.7.0
OS: Debian 9
Web3: 1.0.0-beta.46

@nivida nivida added the Needs Clarification Requires additional input label Feb 20, 2019
@nivida
Copy link
Contributor

nivida commented Feb 20, 2019

Thanks for submitting this issue! I will check it and if required fix it asap.

@rmindo
Copy link

rmindo commented Feb 22, 2019

Same error here.

@nivida nivida added Bug Addressing a bug and removed Needs Clarification Requires additional input labels Feb 26, 2019
@nivida
Copy link
Contributor

nivida commented Feb 27, 2019

@r3dh4r7 I've tried to reproduce this but the error didn't occur. Could you please add the code lines you are using here?

@nivida nivida added more information needed and removed Bug Addressing a bug labels Feb 27, 2019
@dystopiandev
Copy link
Author

@nivida It's basically a loop through addresses from web3.eth.personal.getAccounts(). The following is executed on each iter:

const txObj = await web3.eth.personal.signTransaction({
  gasPrice: web3.utils.toHex(web3.utils.toWei('15', 'gwei')),
  gas: web3.utils.toHex(21000),
  from: BENEFACTORS[i],
  to: BENEFICIARY,
  value: web3.utils.toWei('0.1', 'ether')
}, COMMON_BENEFACTOR_PASSPHRASE)

const tx = await new Promise(resolve => {
  try {
    web3.eth.sendSignedTransaction(txObj.raw)
    .on('receipt', receipt => {
      resolve(receipt)
    })
    .catch((err) => {
      console.log('This does not work', err)
      resolve(false)
    })
  } catch (e) {
    console.log('This does not work either', e)
    resolve(false)
  }
})

Value and gas price are hardcoded here to simplify the snippet. I obtain those dynamically with web3.eth.getBalance(BENEFACTORS[i]) and web3.eth.getGasPrice()
Now, assuming you're testing with changes you've made so far, then there's a possibility that you may have fixed it already.
If you still can't reproduce it with beta 46, then maybe you need to loop through addresses and run the same code, because it doesn't fail every time, but it does turn up in at least 4 runs out of 10.
Maybe it has to do with how the Parity light client responds to requests just a couple of seconds apart? It does say Error cause was EmptyResponse in the stack trace.
I did poke around the validate function and caught the rejection on that block, but other unhandled rejection errors showed up on other lines, indicating that it should've been handled elsewhere that would cover for all.

@mato777
Copy link

mato777 commented Apr 7, 2019

Have the same issue with latest version. I don't get the error even with .on("error", ...) callback. Using async function await with try also give the same error. If I use the raw tx with a curl I am able to see it.

Example of a false spending, the accounts has 0 funds:
// account without 0 funds
const address = '0xaf952c517F20a77b1E2c9522cBe63018925c1C24';
const privateKey = Buffer.from(
"c27a38b3555bc220f004c45033aa955f536b3976a1ce8702eee39ec64ab52ec6",
"hex"
);

const options = {
transactionConfirmationBlocks: 1,
transactionPollingTimeout: 10
};

const Web3 = require("web3");
const web3 = new Web3("http://127.0.0.1:7545/", null, options);
const signer = require("ethereumjs-tx");

async function sendEther() {
const nonce = await web3.eth.getTransactionCount(address);
const txParams = {
nonce: web3.utils.toHex(nonce),
value: web3.utils.toHex(1000),
gasPrice: web3.utils.toHex(1000),
gasLimit: web3.utils.toHex(21000),
to: "0xaf952c517F20a77b1E2c9522cBe63018925c1C24"
};
const rawTx = new signer(txParams);
rawTx.sign(privateKey);
const hexa = "0x" + rawTx.serialize().toString("hex");
let tx = web3.eth.sendSignedTransaction(hexa).on("error", function (error) {
console.log(error);
}).on('receipt', function (receipt) {
console.log(receipt);
});
}

sendEther();

@dystopiandev
Copy link
Author

I just confirmed. This is still an issue as of beta 52.
I have to process.exit() every time the error pops up as there's no way to capture it and it puts the process in limbo.

@nivida
Copy link
Contributor

nivida commented Apr 7, 2019

Will check that tomorrow closer. Thanks for testing it!:)

@JonahGroendal
Copy link

I'm having an issue that might be related. I'm not getting an UnhandledPromiseRejectionWarning but sendSignedTransaction() never resolves. Neither .on('receipt') nor .then() ever get called. I'm using Infura and after calling sendSignedTransaction() (which never resolves) an infinite loop of xhr requests ensues at a rate of about 2 per second.

@nivida
Copy link
Contributor

nivida commented Apr 16, 2019

@JonahGroendal You have to configure the transactionConfirmationBlocks and we have currently an issue with the increasing of the block number over an HTTP connection. #2661

@nivida nivida closed this as completed Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants