Wss://mainnet.infura.io/ws timeout

Looks like the websocket to the mainnet is not responding. These errors are after immediately creating a connection. FWIW, wss://rinkeby.infura.io/ws is fine. Was working fine yesterday all day. Tested from USA and Germany hosts.

[WebSocketConnectReadThread-13] INFO org.web3j.protocol.websocket.WebSocketClient - Opened WebSocket connection to wss://mainnet.infura.io/ws
org.web3j.protocol.core.filters.FilterException: Error sending request
Mon Feb 25 11:49:53 EST 2019
at org.web3j.protocol.core.filters.Filter.throwException(Filter.java:176)
Error sending request
at org.web3j.protocol.core.filters.Filter.run(Filter.java:92)
at org.web3j.protocol.rx.JsonRpc2_0Rx.run(JsonRpc2_0Rx.java:73)
at org.web3j.protocol.rx.JsonRpc2_0Rx.lambda$ethLogFlowable$15(JsonRpc2_0Rx.java:65)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:71)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.Flowable.subscribe(Flowable.java:14416)
at io.reactivex.Flowable.subscribe(Flowable.java:14337)
at org.web3j.sample.SubscribeMainnet.runFilter(SubscribeMainnet.java:66)
at org.web3j.sample.SubscribeMainnet.main(SubscribeMainnet.java:42)
Caused by: java.io.IOException: Request with id 0 timed out
at org.web3j.protocol.websocket.WebSocketService.lambda$setRequestTimeout$32(WebSocketService.java:174)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)

Hi @mneegan are you able to provide a code snippet of how you’re subscribing? That error makes it seem like you aren’t able to make a websocket connection which might have been an ephemeral issue. Are you still having issues on the websocket endpoint now?

Yes still not connecting Here’s my code which is working fine on the Rinkeby version BTW: I’ve even whitelisted my contract
address:

/////////////////////////////////// Connection code: ///////////////////////////////////

Web3j web3j = connect(“wss://mainnet.infura.io/ws/v3/2a9a4f645bf64a378b5352497557e0db”);

private Web3j connect(String url) throws IOException {
Objects.requireNonNull(url, “ethereum.node.url cannot be null”);

Web3j web3j;

//////// WEBSOCKET ///////////////////////////////////
if (url.startsWith(“ws”)) {
WebSocketService web3jService = new WebSocketService(url, true);
web3jService.connect();
web3j = Web3j.build(web3jService);

//////// HTTP ///////////////////////////////////
} else {
web3j = Web3j.build(new HttpService(url));
}

if (log.isDebugEnabled()) {
String clientVersion = web3j.web3ClientVersion().send().getWeb3ClientVersion();
log.debug(“Connected to Ethereum node {} : {}”, url, clientVersion);
}
return web3j;
}

/////////////////////////////////// Subscription code: ///////////////////////////////////

String contractAddress = “0xContractAddressListedHere”;

EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, contractAddress);

web3j.ethLogFlowable(filter).subscribe(log -> {
  System.out.println(log.toString());
  System.out.println(log.getTransactionHash());
  List<Type> args = FunctionReturnDecoder.decode(log.getData(), MY_EVENT.getParameters());
  System.out.println("-----------------------------------------------------------------------------------");
  System.out.println(new Date());
  System.out.println("TxHash : "+log.getTransactionHash());
  System.out.println("Buyer : "+args.get(0).getValue());
  System.out.println("Amount : "+Convert.fromWei(""+args.get(1).getValue(), Convert.Unit.ETHER));
  System.out.println("-----------------------------------------------------------------------------------");
 

}, throwable -> {
  System.out.println(new Date());
  System.out.println(throwable.getMessage());
  throwable.printStackTrace();
  
});

///////////////////////////////////

//================================================

Receives the following error after some pause:

[WebSocketConnectReadThread-13] INFO org.web3j.protocol.websocket.WebSocketClient - Opened WebSocket connection to wss://mainnet.infura.io/ws/v3/2a9a4f645bf64a378b5352497557e0db
Mon Feb 25 18:29:30 EST 2019
Error sending request
org.web3j.protocol.core.filters.FilterException: Error sending request
at org.web3j.protocol.core.filters.Filter.throwException(Filter.java:176)
at org.web3j.protocol.core.filters.Filter.run(Filter.java:92)
at org.web3j.protocol.rx.JsonRpc2_0Rx.run(JsonRpc2_0Rx.java:73)
at org.web3j.protocol.rx.JsonRpc2_0Rx.lambda$ethLogFlowable$15(JsonRpc2_0Rx.java:65)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:71)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.Flowable.subscribe(Flowable.java:14416)
at io.reactivex.Flowable.subscribe(Flowable.java:14337)
at org.web3j.sample.SubscribeMainnet.runFilter(SubscribeMainnet.java:69)
at org.web3j.sample.SubscribeMainnet.main(SubscribeMainnet.java:42)
Caused by: java.io.IOException: Request with id 0 timed out
at org.web3j.protocol.websocket.WebSocketService.lambda$setRequestTimeout$32(WebSocketService.java:174)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)

After investigating, it looks like this is related to an issue with the underlying Ethereum client subscription (pub/sub) implementation. Our engineering team is working on optimizing the log/event system but that work is still ongoing. Unfortunately in the near term these intermittent connection issues may happen. We’ll keep you posted on our progress towards a fix.

Yes, thanks that would be great. I’m able to run this code on parity/geth nodes, but would like to see it implemented here as well. I’d be happy to test it out for you.