truffle icon indicating copy to clipboard operation
truffle copied to clipboard

RuntimeError and then Could not connect to your Ethereum client with truffe > 5.1.49

Open vittominacori opened this issue 4 years ago • 15 comments

  • [ ] I've asked for help in the Truffle Gitter before filing this issue.

Issue

Using truffle > 5.1.49 and I have lot of tests (688) tests don't complete and fail.

Locking version to 5.1.49, or using hardhat, it works.

Actual Results

 Uncaught RuntimeError: abort(TypeError: this.removeListener is not a function). Build with -s ASSERTIONS=1 for more info.
      at process.abort (/Users/vittominacori/.config/truffle/compilers/node_modules/soljson-v0.7.6+commit.7338295f.js:1:13939)
      at process.emit (node_modules/truffle/build/webpack:/node_modules/source-map-support/source-map-support.js:495:1)
      at process.emit (node_modules/truffle/build/webpack:/node_modules/source-map-support/source-map-support.js:495:1)
      at processPromiseRejections (internal/process/promises.js:245:33)
      at processTicksAndRejections (internal/process/task_queues.js:94:32)
      at runNextTicks (internal/process/task_queues.js:62:3)
      at listOnTimeout (internal/timers.js:523:9)
      at processTimers (internal/timers.js:497:7)

and then

     ProviderError: 
Could not connect to your Ethereum client with the following parameters:
    - host       > localhost
    - port       > 8545
    - network_id > 1610811145325
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

Environment

  • Operating System: OSx
  • Truffle v5.1.62 (core: 5.1.62)
  • Solidity - 0.7.6 (solc-js)
  • Node v14.13.0
  • Web3.js v1.2.9

vittominacori avatar Jan 16 '21 15:01 vittominacori

Hi @vittominacori , thanks for bringing this to our attention. Regarding the first issue, can you provide us with some code and specific reproduction steps so we can check it out?

Regarding the Ethereum client issue, do you have ganache running? Truffle test will expect ganache to be running on port 8545. It also looks like you have hard-coded a network id but ganache will run a different network id each time it starts up. You can set network_id to * in your config to see if that addresses the issue.

fainashalts avatar Jan 20 '21 18:01 fainashalts

Hello, this is my truffle config

require('chai/register-should');

const solcStable = {
  version: '0.7.6',
  settings: {
    optimizer: {
      enabled: true,
      runs: 200,
    },
  },
};

const solcNightly = {
  version: 'nightly',
  docker: true,
};

const useSolcNightly = process.env.SOLC_NIGHTLY === 'true';

module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*', // eslint-disable-line camelcase
    },
    coverage: {
      host: 'localhost',
      network_id: '*', // eslint-disable-line camelcase
      port: 8555,
      gas: 0xfffffffffff,
      gasPrice: 0x01,
    },
  },
  compilers: {
    solc: useSolcNightly ? solcNightly : solcStable,
  },
  plugins: ['solidity-coverage'],
};

and below it is how I start ganache

#!/usr/bin/env bash

# Exit script as soon as a command fails.
set -o errexit

# Executes cleanup function at script exit.
trap cleanup EXIT

cleanup() {
  # Kill the ganache instance that we started (if we started one and if it's still running).
  if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then
    kill -9 $ganache_pid
  fi
}

ganache_port=8545

ganache_running() {
  nc -z localhost "$ganache_port"
}

start_ganache() {
  # We define 10 accounts with balance 1M ether, needed for high-value tests.
  local accounts=(
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,1000000000000000000000000"
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,1000000000000000000000000"
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,1000000000000000000000000"
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501203,1000000000000000000000000"
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501204,1000000000000000000000000"
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501205,1000000000000000000000000"
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501206,1000000000000000000000000"
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501207,1000000000000000000000000"
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501208,1000000000000000000000000"
    --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501209,1000000000000000000000000"
  )

  npx ganache-cli --gasLimit 0xfffffffffff --port "$ganache_port" "${accounts[@]}" > /dev/null &

  ganache_pid=$!

  echo "Waiting for ganache to launch on port "$ganache_port"..."

  while ! ganache_running; do
    sleep 0.1 # wait for 1/10 of the second before check again
  done

  echo "Ganache launched!"
}

if ganache_running; then
  echo "Using existing ganache instance"
else
  echo "Starting our own ganache instance"
  start_ganache
fi

npx truffle version

npx truffle test "$@"

The second issue appears after the first one. Any successive test fails with the ProviderError because (I think) the first one causes ganache to close.

It happens within a project that have lot of tests (>500). But everything is ok with project with less tests.

vittominacori avatar Jan 20 '21 19:01 vittominacori

Ok thanks for the steps @vittominacori! We'll go ahead and try to reproduce your error!

eggplantzzz avatar Jan 27 '21 19:01 eggplantzzz

@fainashalts @eggplantzzz

Still having with truffle ^5.2.5

To reproduce clone this repo https://github.com/vittominacori/erc1363-payable-token

and npm run truffle:test

it worked with 5.1.49 and also works with hardhat https://github.com/vittominacori/erc1363-payable-token/runs/2195660016?check_suite_focus=true

  [...]

  Contract: ERC1363
    via transferFromAndCall
      with data
        to a valid receiver contract
          ✓ should call onTransferReceived (2617ms)
      without data
        to a valid receiver contract
          ✓ should call onTransferReceived (108ms)
      testing ERC20 behaviours
        when the sender does not have enough balance
          with data
            ✓ reverts (216ms)
          without data
            ✓ reverts (849ms)
        when the sender has enough balance
          with data
            1) transfers the requested amount
            2) "after each" hook: after test for "transfers the requested amount"


  80 passing (3m)
  2 failing

  1) Contract: ERC1363
       via transferFromAndCall
         testing ERC20 behaviours
           when the sender has enough balance
             with data
               transfers the requested amount:
     
Could not connect to your Ethereum client with the following parameters:
    - host       > localhost
    - port       > 8545
    - network_id > 1616665118015
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

  ProviderError: 
      at Context.<anonymous> (test/token/ERC1363/ERC1363.behaviour.js:85:52)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

  2) Contract: ERC1363
       "after each" hook: after test for "transfers the requested amount":
     ProviderError: 
Could not connect to your Ethereum client with the following parameters:
    - host       > localhost
    - port       > 8545
    - network_id > 1616665118015
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

      at ./node_modules/truffle/build/webpack:/packages/provider/wrapper.js:73:1
      at ./node_modules/truffle/build/webpack:/packages/provider/wrapper.js:102:1
      at XMLHttpRequest.request.onreadystatechange (node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-http/src/index.js:111:1)
      at XMLHttpRequestEventTarget.dispatchEvent (node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
      at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
      at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpRequestError (node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:349:1)
      at ClientRequest.<anonymous> (node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:252:47)
      at Socket.socketErrorListener (_http_client.js:469:9)
      at emitErrorNT (internal/streams/destroy.js:106:8)
      at emitErrorCloseNT (internal/streams/destroy.js:74:3)
      at processTicksAndRejections (internal/process/task_queues.js:80:21)

vittominacori avatar Mar 25 '21 18:03 vittominacori

Is there any update on this issue? Many tests in our complex test suite fail randomly with the same message:

ProviderError: Could not connect to your Ethereum client with the following parameters: - host > 127.0.0.1 - port > 8545 - network_id > 5777 Please check that your Ethereum client: - is running - is accepting RPC connections (i.e., "--rpc" option is used in geth) - is accessible over the network - is properly configured in your Truffle configuration file (truffle-config.js)

  at C:\Users\hdtas\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:73:1
  at C:\Users\hdtas\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:102:1
  at XMLHttpRequest.request.onreadystatechange (C:\Users\hdtas\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3\node_modules\web3-providers-http\lib\index.js:98:1)
  at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\hdtas\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)
  at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (C:\Users\hdtas\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:208:1)
  at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpRequestError (C:\Users\hdtas\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:349:1)
  at ClientRequest.<anonymous> (C:\Users\hdtas\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:252:47)       
  at Socket.socketErrorListener (_http_client.js:469:9)
  at emitErrorNT (internal/streams/destroy.js:106:8)
  at emitErrorCloseNT (internal/streams/destroy.js:74:3)
  at processTicksAndRejections (internal/process/task_queues.js:80:21)

hasandogu avatar Jul 08 '21 01:07 hasandogu

[solved]

I'm having same issue across several different truffle versions from 5.1.x - 5.4.x. Running test files individually everything works but when I run the full test suite I see the above Could not connect to your Ethereum client with the following parameters error on several tests. It is also not deterministic across diff versions, seems to fail at different points

would love any guidance!


Edit - stopped seeing issue at 5.4.11 (still saw up to 5.4.1)

SidSethi avatar Sep 20 '21 22:09 SidSethi

[solved]

I'm having same issue across several different truffle versions from 5.1.x - 5.4.x. Running test files individually everything works but when I run the full test suite I see the above Could not connect to your Ethereum client with the following parameters error on several tests. It is also not deterministic across diff versions, seems to fail at different points

would love any guidance!

Edit - stopped seeing issue at 5.4.11 (still saw up to 5.4.1)

I still has the problem at 5.4.15 Is there any solution?

Hanggi avatar Oct 20 '21 05:10 Hanggi

Maybe you should restart you computer(windows)? I have solved it by this way.

cpcchengt avatar Feb 21 '22 09:02 cpcchengt

I also have same problem with lots of tests and lots of blockchain events in them. Now I use truffle 5.5.5 and used older versions with same issue. When I run multiple tests in random moments of time I get could not connect to your Ethereum client with the following parameters. Truffle uses web3 provider. As for version of 5.5.5 it uses web3 version 1.5.3. You can install newer version (as for me I use web3 1.7.1) and tell truffle to use it in truffle-config.js like this networks: { ganache: { provider: function() { return new Web3.providers.HttpProvider("http://host:port"); }, } } This solved the problem.

Moreover, when I use truffle with external web3 provider and flag --show-events I also get an error Could not connect to your Ethereum client. Please check that your Ethereum client: at random moments of time. And I do not get any errors without this flag. Maybe it would help to find the problem...

AlexeyBarsuk avatar Mar 19 '22 18:03 AlexeyBarsuk

Fixed this problem by configuring truffle to use a more recent version of web3 (as suggested by @AlexeyBarsuk).

Install web3 if not already in your deps (worked for me with 1.7.1)

yarn add -D web3

Update truffle-config.js to include provider field:

const Web3 = require("web3");

module.exports = {
  // ...
  networks: {
    development: {
      provider: () => new Web3.providers.HttpProvider("http://127.0.0.1:7545"),
      host: "127.0.0.1",
      port: 7545,
      network_id: "*",
    },
    // ...
  },
  // ...
}

chrisdrifte avatar Mar 24 '22 12:03 chrisdrifte

This seems very strange to me. Does anyone have a sample project on GitHub that I could check out that works with web3 1.7.1 but that does not work otherwise? I would love to try and dig a little deeper on this.

eggplantzzz avatar Mar 24 '22 14:03 eggplantzzz

I have used this in my truffle-config.js

const Web3 = require("web3");

module.exports = {
  // ...
  networks: {
    development: {
      provider: () => new Web3.providers.HttpProvider("http://127.0.0.1:7545"),
      host: "127.0.0.1",
      port: 7545,
      network_id: "*",
    },
    // ...
  },
  // ...
}

I still get the same error so that is not helping.

bater53 avatar Jun 14 '22 17:06 bater53

I am also running into this issue on a Mac. Tried explicitly adding web3 and the provider, but didn't resolve the issue for me.

     ProviderError: 
Could not connect to your Ethereum client.
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

      at webpack:///./packages/provider/wrapper.js:73:1
      at webpack:///./packages/provider/wrapper.js:102:1
      at XMLHttpRequest.request.onreadystatechange (webpack:///./node_modules/web3/node_modules/web3-providers-http/lib/index.js:98:1)
      at XMLHttpRequestEventTarget.dispatchEvent (webpack:///./node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
      at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (webpack:///./node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
      at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpRequestError (webpack:///./node_modules/xhr2-cookies/dist/xml-http-request.js:349:1)
      at ClientRequest.<anonymous> (webpack:///./node_modules/xhr2-cookies/dist/xml-http-request.js:252:47)
      at ClientRequest.emit (node:events:526:28)
      at ClientRequest.emit (node:domain:475:12)
      at Socket.socketErrorListener (node:_http_client:442:9)
      at Socket.emit (node:events:526:28)
      at Socket.emit (node:domain:475:12)
      at emitErrorNT (node:internal/streams/destroy:157:8)
      at emitErrorCloseNT (node:internal/streams/destroy:122:3)
      at processTicksAndRejections (node:internal/process/task_queues:83:21)

stuartwk avatar Jun 16 '22 08:06 stuartwk

Hey @stuartwk, It's unclear if you are experiencing the same error as the OP. Please open a new issue with reproduction steps if possible.

cds-amal avatar Jun 16 '22 11:06 cds-amal

Hey everyone, can you try using latest truffle and let us know if you're still experiencing issues.

cds-amal avatar Aug 04 '22 18:08 cds-amal

Closing for issue maintenance.

eggplantzzz avatar Aug 11 '22 17:08 eggplantzzz

@cds-amal I have the same issue and can confirm It still happens with the latest version.

itsMarcoSolis avatar Sep 14 '22 04:09 itsMarcoSolis

This Good!!!

development: {
  provider: () => new Web3.providers.HttpProvider("http://127.0.0.1:7545"),
  host: "127.0.0.1",     // Localhost (default: none)
  port: 7545,            // Standard Ethereum port (default: none)
  network_id: "*",       // Any network (default: none)
  websockets: true

},

maaeyeng avatar Nov 01 '22 02:11 maaeyeng

I fixed this issue with the same solution adding the provider from Web3 in your truffle config seems to solve the issue.


module.exports = {
  // ...
  networks: {
    development: {
      provider: () => new Web3.providers.HttpProvider("http://127.0.0.1:8545"),
      host: "127.0.0.1",
      port: 8545,
      network_id: "*",
    },
    // ...
  },
  // ...
}```

MysticDakra avatar Nov 09 '22 19:11 MysticDakra

You do realize that you can change the port number to 8545? It is just that simple. Just check what truffle is pointing at for the point and change it to that port or change the port in the truffle settings to 7545, Not difficult. I hope this helps.

On Wed, Nov 9, 2022 at 2:12 PM Dakra-Mystic @.***> wrote:

I fixed this issue with the same solution...

module.exports = { // ... networks: { development: { provider: () => new Web3.providers.HttpProvider("http://127.0.0.1:7545"), host: "127.0.0.1", port: 7545, network_id: "*", }, // ... }, // ... }```

— Reply to this email directly, view it on GitHub https://github.com/trufflesuite/truffle/issues/3710#issuecomment-1309238479, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELLPFRY2GPE2WKNARYZV73WHPZTBANCNFSM4WFLJFUQ . You are receiving this because you commented.Message ID: @.***>

bater53 avatar Nov 09 '22 19:11 bater53

You do realize that you can change the port number to 8545? It is just that simple. Just check what truffle is pointing at for the point and change it to that port or change the port in the truffle settings to 7545, Not difficult. I hope this helps. On Wed, Nov 9, 2022 at 2:12 PM Dakra-Mystic @.> wrote: I fixed this issue with the same solution... module.exports = { // ... networks: { development: { provider: () => new Web3.providers.HttpProvider("http://127.0.0.1:7545"), host: "127.0.0.1", port: 7545, network_id: "", }, // ... }, // ... }``` — Reply to this email directly, view it on GitHub <#3710 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELLPFRY2GPE2WKNARYZV73WHPZTBANCNFSM4WFLJFUQ . You are receiving this because you commented.Message ID: @.*>

The port number wasnt the issue, I had mine set at 8545 as well the problem was the provider.

MysticDakra avatar Nov 09 '22 19:11 MysticDakra

Sorry I responded. I won't the next time.

---------- Forwarded message --------- From: Dakra-Mystic @.> Date: Wed, Nov 9, 2022 at 2:32 PM Subject: Re: [trufflesuite/truffle] RuntimeError and then Could not connect to your Ethereum client with truffe > 5.1.49 (#3710) To: trufflesuite/truffle @.> Cc: Byron Stephen Ater @.>, Comment < @.>

You do realize that you can change the port number to 8545? It is just that simple. Just check what truffle is pointing at for the point and change it to that port or change the port in the truffle settings to 7545, Not difficult. I hope this helps. … <#m_-989763510068248865_> On Wed, Nov 9, 2022 at 2:12 PM Dakra-Mystic @.*> wrote: I fixed this issue with the same solution... module.exports = { // ... networks: { development: { provider: () => new Web3.providers.HttpProvider("http://127.0.0.1:7545 http://127.0.0.1:7545"), host: "127.0.0.1", port: 7545, network_id: "", }, // ... }, // ... }``` — Reply to this email directly, view it on GitHub <#3710 (comment) https://github.com/trufflesuite/truffle/issues/3710#issuecomment-1309238479>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELLPFRY2GPE2WKNARYZV73WHPZTBANCNFSM4WFLJFUQ https://github.com/notifications/unsubscribe-auth/AELLPFRY2GPE2WKNARYZV73WHPZTBANCNFSM4WFLJFUQ . You are receiving this because you commented.Message ID: @.**>

The port number wasnt the issue, I had mine set at 8545 as well the problem was the provider.

— Reply to this email directly, view it on GitHub https://github.com/trufflesuite/truffle/issues/3710#issuecomment-1309258483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELLPFVNGKX6LH2N4X7XGOLWHP34FANCNFSM4WFLJFUQ . You are receiving this because you commented.Message ID: @.***>

bater53 avatar Nov 09 '22 19:11 bater53