Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

"UnhandledPromiseRejectionWarning: Error: Wrong response id" with async #4392

Closed
dlscjf151 opened this issue Sep 26, 2021 · 4 comments
Closed
Labels
1.x 1.0 related issues Investigate Stale Has not received enough activity

Comments

@dlscjf151
Copy link

dlscjf151 commented Sep 26, 2021

I want to call about 1000 methods at the same time by async.
However I encountered this error.
Why did the error occur?
How can I fix it?

my code

async function a() {
    let Web3 = require('web3')
    let web3 = new Web3('https://bsc-dataseed1.binance.org:443')

    let arr = Array.apply(null, Array(1000)).map(function () {})
    let tasks = []
    let data = "0x9b6e56c9"

    arr.map(x => {
        tasks.push(web3.eth.call({to: "0x6f9646a8e5Bf4AC7b71D9BB0F21159112AdB572d", data: data}))
    })
    await Promise.all(tasks)
}

error thrown

(node:25504) UnhandledPromiseRejectionWarning: Error: Wrong response id 207 (expected: 205) in {"jsonrpc":"2.0","id":205,"method":"eth_call","params":[{"to":"0x6f9646a8e5bf4ac7b71d9bb0f21159112adb572d","data":"0x9b6e56c9"},"latest"]}
    at C:\WebstormProjects\untitled\node_modules\web3-core-requestmanager\lib\index.js:296:29
    at XMLHttpRequest.request.onreadystatechange (C:\WebstormProjects\untitled\node_modules\web3-providers-http\lib\index.js:98:13)
    at XMLHttpRequestEventTarget.dispatchEvent (C:\WebstormProjects\untitled\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (C:\WebstormProjects\untitled\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (C:\WebstormProjects\untitled\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (C:\WebstormProjects\untitled\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61)
    at IncomingMessage.emit (events.js:412:35)
    at endReadableNT (internal/streams/readable.js:1317:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:25504) 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(). T
o terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:25504) [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.
@jdevcs jdevcs added the 1.x 1.0 related issues label Sep 27, 2021
@jdevcs
Copy link
Contributor

jdevcs commented Sep 27, 2021

Thanks for reporting, this is not always reproducible, Only occurred once randomly for me:

(node:9705) UnhandledPromiseRejectionWarning: Error: Wrong response id 546 (expected: 552) in {"jsonrpc":"2.0","id":552,"method":"eth_call","params":[{"to":"0x6f9646a8e5bf4ac7b71d9bb0f21159112adb572d","data":"0x9b6e56c9"},"latest"]} at //node_modules/web3-core-requestmanager/lib/index.js:296:29 ....

Mismatching result is passed to callback so this doesnt match, might be provider not sending result in correct sequence. This needs investigation.

@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 Nov 27, 2021
@lodembeep
Copy link

lodembeep commented Mar 19, 2023

i deleted my answer because i figured out the reason, it was because i did hit the rate limit with my endpoint provider.

Maybe the requestmanager should also return the result content to show the difference.
i found out about it this way :

RequestManager.prototype._jsonrpcResultCallback = function (callback, payload) {
    return function (err, result) {
        if (result && result.id && payload.id !== result.id) {
            console.log("dumping everything : ");
            console.log("RESULT :", result);
            console.log("PAYLOAD :", payload);
            return callback(new Error('Wrong response id ${result.id} (expected: ${payload.id}) in ${JSON.stringify(payload)}'));
        }
        if (err) {
            return callback(err);
        }
        if (result && result.error) {
            return callback(errors.ErrorResponse(result));
        }
        if (!Jsonrpc.isValidResponse(result)) {
            return callback(errors.InvalidResponse(result));
        }
        callback(null, result.result);
    };
};

in the result i found a response saying that i reached the rate limit.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
1.x 1.0 related issues Investigate Stale Has not received enough activity
Projects
None yet
Development

No branches or pull requests

4 participants
@dlscjf151 @lodembeep @jdevcs and others