f-o-a-m / purescript-web3

a purescript library for the web3 api
Apache License 2.0
127 stars 24 forks source link

Invalid JSON RPC response from provider response: "" responseURL: undefined status: 0 #157

Closed srghma closed 2 years ago

srghma commented 2 years ago

https://github.com/ethjs/ethjs-provider-http/blob/03f911db08757bd5edeb5b613255a25df0124d84/src/index.js#L16

https://pastebin.com/QvhJBTVN

https://asciinema.org/a/466689

this error is reproducible on "Case [Past, ∞] With Trail" test (I can disable all other tests with itOnly method and it will fail)

 ~/projects/purescript-web3   master ±  cat src/Network/Ethereum/Web3/JsonRPC.js

"use strict";

var req = typeof module === "undefined" ? undefined : module.require;
var util = req === undefined ? undefined : req("util");

exports._sendAsync = function (provider) {
    return function (request) {
        return function(onError, onSuccess) {
            provider.sendAsync(request, function(err, succ) {
                if (err) {
                  const x = { request, err, succ }
                  console.log('!!!!', util.inspect(x, { depth: null, colors: true }));
                  onError(err);
                } else {
                  if (request.method === 'eth_getLogs') {
                    console.log(`eth_getLogs ${request.params[0].fromBlock}-${request.params[0].toBlock}: ${util.inspect(succ.result, { depth: null, colors: true })}`);
                  } else if (request.method === 'eth_blockNumber') {
                    console.log(`eth_blockNumber: ${succ.result}`);
                  } else if (request.method === 'eth_getTransactionReceipt') {
                    console.log(`eth_getTransactionReceipt ${request.params[0].slice(0, 8)}: ${succ.result}`);
                  } else {
                    console.log(request.method, util.inspect(succ, { depth: null, colors: true }));
                  }
                  onSuccess(succ);
                }
            });
            return function (cancelError, onCancelerError, onCancelerSuccess) {
                onCancelerSuccess();
            };
        };
    };
};

maybe my computer is too fast -> too many eth_blockNumber, eth_getLogs -> geth just fails

TODO:

srghma commented 2 years ago

https://asciinema.org/a/466716

yes, test doesn't fail anymore if I add delay

 ~/projects/purescript-web3  ➦ 222a2aa ±✚  git diff | cat
diff --git a/src/Network/Ethereum/Web3/JsonRPC.purs b/src/Network/Ethereum/Web3/JsonRPC.purs
index a69b36f..3d9ca02 100644
--- a/src/Network/Ethereum/Web3/JsonRPC.purs
+++ b/src/Network/Ethereum/Web3/JsonRPC.purs
@@ -1,14 +1,15 @@
 module Network.Ethereum.Web3.JsonRPC where

 import Prelude
-import Effect.Aff (Aff, Error, attempt, error)
-import Effect.Aff.Class (liftAff)
-import Effect.Aff.Compat (fromEffectFnAff, EffectFnAff)
+
 import Control.Monad.Error.Class (throwError)
 import Control.Monad.Except (runExcept)
 import Control.Monad.Reader (ask)
 import Data.Array ((:))
 import Data.Either (Either(..))
+import Effect.Aff (Aff, Error, Milliseconds(..), attempt, delay, error)
+import Effect.Aff.Class (liftAff)
+import Effect.Aff.Compat (fromEffectFnAff, EffectFnAff)
 import Foreign (Foreign)
 import Foreign.Class (class Decode, class Encode, decode, encode)
 import Foreign.Generic (defaultOptions, genericEncodeJSON)
@@ -25,7 +26,9 @@ class Remote a where
 instance remoteBase :: (Decode a) => Remote (Web3 a) where
   remote_ f = do
     p <- ask
-    res' <- liftAff $ attempt $ f p mempty
+    res' <- liftAff $ attempt do
+       delay (Milliseconds 300.0)
+       f p mempty
     case res' of
       Left uncheckedErr -> throwError $ asError $ RemoteError $ show uncheckedErr
       Right res -> case runExcept $ decode res of

prob we know how to solve - filters should use delay