web3.js日志监控报错:Provider started to reconnect before the response got received!
本文关键字: reconnect, web3, web3.js当遇到网络不稳定的时候,会偶发出现这个报错,有时候会重连上,但是有时候就直接在这个报错这里卡住。解决办法是把options参数补齐优化。 见如下官方示例代码
// ==========
// Websockets
// ==========
var Web3WsProvider = require('web3-providers-ws');
var options = {
timeout: 30000, // ms
// Useful for credentialed urls, e.g: ws://username:password@localhost:8546
headers: {
authorization: 'Basic username:password'
},
clientConfig: {
// Useful if requests are large
maxReceivedFrameSize: 100000000, // bytes - default: 1MiB
maxReceivedMessageSize: 100000000, // bytes - default: 8MiB
// Useful to keep a connection alive
keepalive: true,
keepaliveInterval: 60000 // ms
},
// Enable auto reconnection
reconnect: {
auto: true,
delay: 5000, // ms
maxAttempts: 5,
onTimeout: false
}
};
var ws = new Web3WsProvider('ws://localhost:8546', options);