Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Specifying "localhost" in server.listen does not work. #3491

Open
gluax opened this issue Aug 3, 2022 · 7 comments
Open

Specifying "localhost" in server.listen does not work. #3491

gluax opened this issue Aug 3, 2022 · 7 comments

Comments

@gluax
Copy link

gluax commented Aug 3, 2022

The following does not work but likely should mimic common behavior between other js libs.

 let server = Ganache.server();
server.listen(8888, 'localhost');

There's no direct error and everything seems to function. However, after deploying a contract and trying to make calls to it(at least with the ethers lib from my own testing) results in an Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.6.8).

However, the following works as expected.

 let server = Ganache.server();
server.listen(8888, '127.0.0.1');

For consistency/commonly thought of behavior 'localhost' should provide the same behavior as directly writing out the localhost address.

@AbnerZheng
Copy link

AbnerZheng commented Aug 4, 2022

I have tested it, and 'localhost' works in my own desktop.

The mapping from localhost to 127.0.0.1 is done by the hosts file in *nix system, check /etc/hosts,adding one line 127.0.0.1 localhost, it might works.

@davidmurdoch
Copy link
Member

@gluax what OS are you running? @AbnerZheng what OS are you running?

@gluax
Copy link
Author

gluax commented Aug 4, 2022

I'm running on Windows 10.

@AbnerZheng
Copy link

I'm running on macos.

@davidmurdoch davidmurdoch changed the title Specifying 'localhost' in server.listen Does not work. Specifying "localhost" in server.listen does not work. Aug 5, 2022
@davidmurdoch davidmurdoch moved this from Inbox to Backlog in Ganache Aug 18, 2022
@davidmurdoch
Copy link
Member

davidmurdoch commented Nov 15, 2022

This may be related to this Node bug: nodejs/node#40702

@benjamincburns
Copy link
Contributor

Assuming that the issue is caused by nodejs/node#40702, you may find that the problem abates on node 16.x.x. You may also find that if you check the output of lsof -i -P | grep LISTEN | grep 8545, the node process that hosts ganache will be listening on IPv6 (usually the 5th column in the output).

We just encountered and fixed what's likely the same issue with the Truffle dashboard. I wrote up a fairly in-depth explanation of the problem on the related issue at trufflesuite/truffle#5690, and the fix can be seen at trufflesuite/truffle#5699.

@OnlyOneJMJQ
Copy link
Contributor

I think this is related, on my machine (which, for context, produced the error @benjamincburns is referencing) if I run ganache on localhost and my truffle-config is set to 127.0.0.1 I get the error:

Could not connect to your Ethereum client with the following parameters:
    - host       > 127.0.0.1
    - port       > 8888
    - network_id > *

If I change my truffle-config to use localhost as well, then it will work. This leads me to believe it is the IP resolution issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

5 participants