eth_getFilterChanges should rebuild the filter if the filter is invalid
This affects observables that poll for new data from the node using eth_getFilterChanges. Currently, if an exception is thrown the observable tries again, which is fine if there was some SocketException. However, if the node was to be restarted, the filter becomes invalid but web3j continues to poll with the invalid filter indefinitely.
The Filter class is throwing the exception.
Regarding the following exception:
15:26:26.205 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - --> POST <MYSECRETNODE> http/1.1
15:26:26.205 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - Content-Type: application/json; charset=utf-8
15:26:26.205 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - Content-Length: 109
15:26:26.205 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService -
15:26:26.205 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - {"jsonrpc":"2.0","method":"eth_getFilterChanges","params":["0x3ca672eecb7329eaac5d2ee0c55a6f46"],"id":828471}
15:26:26.205 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - --> END POST (109-byte body)
15:26:26.348 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - <-- 200 OK <MYSECRETNODE> (143ms)
15:26:26.348 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - Content-Type: application/json
15:26:26.348 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - Date: Tue, 16 Jan 2018 15:26:26 GMT
15:26:26.348 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - Content-Length: 83
15:26:26.348 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService -
15:26:26.348 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - {"jsonrpc":"2.0","id":828471,"error":{"code":-32000,"message":"filter not found"}}
15:26:26.348 [pool-2-thread-2] DEBUG org.web3j.protocol.http.HttpService - <-- END HTTP (83-byte body)
15:26:26.348 [pool-2-thread-2] ERROR o.w.protocol.core.filters.Filter - Error sending request
org.web3j.protocol.core.filters.FilterException: Invalid request: Unknown Error
at org.web3j.protocol.core.filters.Filter.throwException(Filter.java:154)
at org.web3j.protocol.core.filters.Filter.pollFilter(Filter.java:113)
at org.web3j.protocol.core.filters.Filter.lambda$run$18(Filter.java:75)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
This issue comes as a result of fixing #279
I recently encountered the same problem when I had to update and restart my geth node. Is there any way to catch this exception from the filter and make a new filter?
What you describe is what needs to be implemented @Daantie
The same problem. Did somebody find solution?
Currently you need to rebuild the observable if this happens. We would welcome a PR to rebuild the filter in Web3j so users don't have to worry about this.
I face this issue regularly, and it is very annoying. As this happens internally, inside the polling of web3j itself, the user doesn’t even has the easy way to learn that something bad happened, and that they need to (try) to rebuild the observable.
But actually, this issue opens a huge can of worms. Sorry to say, but the existing logic of filter polling is unreliable and needs major hardening (which would hopefully fix this #359 issue itself). Let me explain:
At the moment, the polling itself happens within core/filters/Filter.java. scheduledExecutorService.scheduleAtFixedRate invokes pollFilter(); which does web3j.ethGetFilterChanges(filterId).send();.
On any issue (the ones I face were java.net.SocketTimeoutException: timeout and java.net.SocketException: Socket closed, but there may be any others), this code just grumbles in the logs and skips to the next iteration of ethGetFilterChanges.
The problem is when the faulty iteration succeeded in sending the eth_getFilterChanges command to Ethereum node (and the node ran it), but failed in transmitting the node response (for some network failure). This will mean that the filter changes that failed to be delivered on the problematic iteration, are gone forever. The next iteration will report only the notifications after them, but not them anymore.
My opinion is that, if something failed during the filter polling (especially due to the network failures), we cannot just ignore it; the poller needs to know about the last successfully delivered data. So if the poller fails, it has to 1. rebuild the filter (because there could have been a Ethereum node restart), 2. reread the logs and make sure to replay everything that hasn’t get delivered during eth_getFilterChanges response transmission.
Until this, the whole filter logic should be considered unreliable and prone to lose the events.
@amyodov agreed, however it is still possible to perform this "hardening" by the user. Either way, this should be handled by web3j, but it is not on my priority list at this time. If someone from the community could pick up this issue and propose a PR we can move the discussion forward.
Hello. I made some fix in my web3j fork library. Now when we got error during polling ethereum filter. Exception will submited to Subscriber#exception method and we can handle it how we want. It's works for me. I know that it's solution isn't perfect, but it's enough for my project. Here link on my fork: https://github.com/upers/web3j
Hi , I am using the following BlockObservable , and i am facing the same error . Here is the code
Web3j web3j = Web3j.build(new HttpService(envConfiguration.getEthereumServerUrl()));
blockSubscription = web3j.blockObservable(false).subscribe(
blockObserver);
` private static Subscriber
@Override
public void onCompleted() {
LOGGER.info("complete event called");
}
@Override
public void onError(Throwable e) {
LOGGER.info("error listening block");
}
@Override
public void onNext(EthBlock t) {
LOGGER.info("block fetched");
}
};`
Now in the above code , the onError function gets called only initially , that is if geth is not running on the BlockObservable initialisation , but if i restart geth , i face the ABOVE mentioned issue.
How will i rebuild the Observable ? I even updated the dependency to 3.4.0 . But i am stuck.
I had a similar problem. I had to rewrite web3j a little so that it would throw an exception into the method onError action. Here link on my commit: https://github.com/upers/web3j/commit/f1869d7f75a53535dbe4dc83c4588a52f8fee62d
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
This issue now has a funding of 250.0 DAI (250.0 USD @ $1.0/DAI) attached to it.
- If you would like to work on this issue you can 'start work' on the Gitcoin Issue Details page.
- Questions? Checkout Gitcoin Help or the Gitcoin Slack
- $26,310.00 more funded OSS Work available on the Gitcoin Issue Explorer
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
Work has been started.
These users each claimed they can complete the work by 7 months, 3 weeks ago. Please review their action plans below:
1) upers has been approved to start work.
Got error code from RPC. If code -32000 then resubscribe.
Learn more on the Gitcoin Issue Details page.
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
Work for 250.0 DAI (250.0 USD @ $1.0/DAI) has been submitted by:
@ceresstation please take a look at the submitted work:
- Learn more on the Gitcoin Issue Details page
- Questions? Checkout Gitcoin Help or the Gitcoin Slack $18,730.83 more funded OSS Work available on the Gitcoin Issue Explorer
Hey there @upers, PRs look great overall but there are a couple of small issues pointed out by @conor10, happy to distribute the funds once those are done :)
Done. https://github.com/web3j/web3j/pull/614
@ceresstation and @conor10, have you had chance to review latest from @upers? Would love to pay him out for the work :)
My commit was merge to master. https://github.com/web3j/web3j/pull/614
@upers Just saw that upers, sorry for the delay here, you're paid out 🎉
@ceresstation Thanks, but I still don't see tokens on my address: 0x96c892cd40d2fae76fd0e65fe3da471abe16cf84
@upers ah it was an issue with the gas price I set given network congestion, you should receive it soon
Fixed in https://github.com/web3j/web3j/pull/614.