WebSocketProvider error. WS_ERR_UNSUPPORTED_MESSAGE_LENGTH
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
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?