Web3.js: UnhandledPromiseRejectionWarning on sendSignedTransaction

Created on 19 Feb 2019  路  9Comments  路  Source: ChainSafe/web3.js

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

more information needed

Most helpful comment

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.

All 9 comments

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

Same error here.

@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 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.

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();

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.

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

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.

@JonahGroendal You have to configure the transactionConfirmationBlocks and we have currently an issue with the increasing of the block number over an HTTP connection. https://github.com/ethereum/web3.js/issues/2661

Was this page helpful?
0 / 5 - 0 ratings