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

Batch requests over ws fails with RPC response {} #4581

Closed
1 task done
herenickname opened this issue Nov 26, 2021 · 9 comments
Closed
1 task done

Batch requests over ws fails with RPC response {} #4581

herenickname opened this issue Nov 26, 2021 · 9 comments
Labels
1.x 1.0 related issues Bug Addressing a bug Stale Has not received enough activity

Comments

@herenickname
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When I do a batch request with websocket-initialized web3, I get an error:

root@dedicated:/root# ts-node src/index
/root/src/classes/BlocksFetcher.ts:111
            throw new Error(error)
                  ^
Error: Error: Invalid JSON RPC response: {}
    at BlockFetcherJob.processBlock (/root/src/classes/BlocksFetcher.ts:111:19)
    at Object.cb [as callback] (/root/src/classes/BlocksFetcher.ts:96:47)
    at /root/node_modules/web3-core-requestmanager/lib/batch.js:55:44
    at Array.forEach (<anonymous>)
    at /root/node_modules/web3-core-requestmanager/lib/batch.js:49:12
    at Object.callback (/root/node_modules/web3-core-requestmanager/lib/index.js:181:20)
    at /root/node_modules/web3-providers-ws/lib/index.js:161:21
    at Map.forEach (<anonymous>)
    at WebsocketProvider._onClose (/root/node_modules/web3-providers-ws/lib/index.js:160:28)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (/root/node_modules/yaeti/lib/EventTarget.js:115:12)
    at W3CWebSocket.onClose (/root/node_modules/websocket/lib/W3CWebSocket.js:228:10)
    at WebSocketConnection.<anonymous> (/root/node_modules/websocket/lib/W3CWebSocket.js:201:17)
    at WebSocketConnection.emit (node:events:390:28)
    at WebSocketConnection.emit (node:domain:475:12)
    at WebSocketConnection.drop (/root/node_modules/websocket/lib/WebSocketConnection.js:475:14)
    at /root/node_modules/websocket/lib/WebSocketConnection.js:303:18 

The problem only with websocket connection. Over http batch requests are works.

Single requests over websocket are working properly.

Expected Behavior

To get a complete response

Steps to Reproduce

const web3 = new Web3('ws://geth_host:geth_ws_port')

const batch = new web3.BatchRequest()

for (let blockNumber = 0; blockNumber <= 10_000; blockNumber++) {
    const func = web3.eth.getBlock
    const cb = (error, block) => processBlock(error, block, blockNumber)

    const toProcess = func.request(blockNumber, { name: blockNumber }, cb)
    batch.add(toProcess)
}

batch.execute()

Web3.js Version

1.6.1

Environment

  • Operating System: Ubuntu 21.04
  • Node.js Version: v16.13.0
  • NPM Version: 8.1.0

Anything Else?

No response

@herenickname herenickname added the Bug Addressing a bug label Nov 26, 2021
@luu-alex luu-alex added the 1.x 1.0 related issues label Nov 26, 2021
@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 Jan 26, 2022
@herenickname
Copy link
Author

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.

mistake

@github-actions github-actions bot removed the Stale Has not received enough activity label Jan 27, 2022
@Jasonb911
Copy link

Fucken goofs

@cleivson
Copy link

Same issue here. I guess this may be by design but I couldn't find any docs about it

@cleivson
Copy link

From debugging I found that https://github.com/ChainSafe/web3.js/blob/1.x/packages/web3-providers-ws/src/index.js#L310 sends a single message with the id of the first request but the node responds every message individually in https://github.com/ChainSafe/web3.js/blob/1.x/packages/web3-providers-ws/src/index.js#L125 and then RequestManager fails the validation for a result array: https://github.com/ChainSafe/web3.js/blob/1.x/packages/web3-core-requestmanager/src/index.js#L207

@cleivson
Copy link

I'm using a QuickNode node over WS, maybe they implement it like this because they charge over responses?

@khaledosman
Copy link

khaledosman commented May 4, 2022

I have the same issue, I also noticed that this only happens if I have alot of calls in my batch request (I was trying to do 500), if I limit it to 5 only, the request works. 🤷

Anyone found a solution/workaround? I guess chunk the batch requests over a time duration?

@khaledosman
Copy link

update: I was using ganache locally, seems to work fine after switching my provider rpc url to one from rivet

@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 Jul 15, 2022
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 Stale Has not received enough activity
Projects
None yet
Development

No branches or pull requests

5 participants