ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

WebSocketProvider error. WS_ERR_UNSUPPORTED_MESSAGE_LENGTH

Open whytereshchenko opened this issue 1 year ago • 1 comments

Ethers Version

6.13.2

Search Terms

ws, websockets, message_length

Describe the Problem

We have an uncaught exception from the ethers library when calling the method provider.getBlock() or provider.getLogs(). We can't determine where this error occurs or what causes it. I suspect that the ethers library is not catching this error.

Could this be caused by a large number of blocks, as my function processMissedBlocks() processes a thousand blocks for each of the six networks?

How to handle this?

We just moved to v6 from v5.

Provider initialization:

 Provider: new ethers.WebSocketProvider(`url`, ethers.Network.from(56), {
                polling: true,
                staticNetwork: true,
            }),

Code Snippet

private async processingLogs(token: DepositToken, filter: {address: string, fromBlock: number, toBlock: number, topics: string[]}, txHash?: string) {
        const provider = this.provider[token.network];
        let events = await provider.getLogs(filter).catch((e) => {
            transactionsLogger.error(e)
        });

        if(!events) return;

        const indexTxHash = txHash ? events.findIndex(log => log.transactionHash === txHash) : -1;
        if (indexTxHash !== -1) {
            events = events.slice(indexTxHash+1);
        }

        for (const event of events) {
            this.processContractEvent(token, event);
        }
    }


 private async processBlock(provider: Provider, token: DepositToken, blockNumber: number) {
        const block = await provider.getBlock(blockNumber, true).catch((e) => {
            transactionsLogger.error(e)
        });

      // process logic
}

Contract ABI

No response

Errors

Error: {"code":1,"reason":{"code":"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"},"signal":"uncaughtException"}

Environment

node.js (v12 or newer)

Environment (Other)

QuickNode

whytereshchenko avatar Aug 08 '24 14:08 whytereshchenko

Both v5 and v6 use the same ws library in Node for handling WebSockets.

There is a recent security fix to the ws package though, but I don't think that is related.

Can you try adding provider.on("debug", console.log) and trigger the error to see what bytes are going/coming over the wire when it happens?

ricmoo avatar Oct 16 '24 01:10 ricmoo