Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hardhat node fails to detect IPv6 port collision #6333

Closed
tmigone opened this issue Feb 18, 2025 · 1 comment
Closed

hardhat node fails to detect IPv6 port collision #6333

tmigone opened this issue Feb 18, 2025 · 1 comment
Assignees

Comments

@tmigone
Copy link
Contributor

tmigone commented Feb 18, 2025

Version of Hardhat

2.22.18

What happened?

It looks like hh node checks for port collisions on 127.0.01 IPv4 interface and will fail to start if a conflict is detected. However, it does not check for potential collisions on IPv6 interfaces, allowing it to start without a warning even when another process is already bound to the same port on IPv6.

Here you can see an example with an anvil chain node running on docker and a hardhat node running alongside, both listening to port 8545 but bound to different interfaces:

tomi@ceres:horizon$ lsof -nP -iTCP -sTCP:LISTEN | grep 8545
com.docke 35920 tomi  118u  IPv6 0x98a77bb67aed0736      0t0  TCP *:8545 (LISTEN)
node      39692 tomi   22u  IPv4 0x261ffeff05f992b7      0t0  TCP 127.0.0.1:8545 (LISTEN)

Now this might not be considered a bug but it's very inconvenient and confusing, specially considering that hardhat node only binds to 127.0.0.1 meaning any requests made to localhost will actually be handled by the anvil node.

Here is example output for the same RPC request using different interfaces (anvil node is configured to use chainId=0x539 and hardhat node uses chainId=0x7a69):

tomi@ceres:horizon$ curl -X POST http://127.0.0.1:8545 \
     -H "Content-Type: application/json" \
     --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
{"jsonrpc":"2.0","id":1,"result":"0x7a69"}

tomi@ceres:horizon$ curl -X POST http://localhost:8545 \
     -H "Content-Type: application/json" \
     --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
{"jsonrpc":"2.0","id":1,"result":"0x539"}

tomi@ceres:horizon$ curl -X POST http://\[::1]:8545 \
     -H "Content-Type: application/json" \
     --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
{"jsonrpc":"2.0","id":1,"result":"0x539"}

A bit more info that might be useful:

  • Running macOS 14.5
  • Docker engine 27.5.1 / Docker compose 2.32.4
  • All network interface configurations are just using defaults, no special config

Minimal reproduction steps

To reproduce:

  1. Start a chain test node on a docker container, see attached docker-compose.yml configuration
  2. Run hh node on any hardhat project
  3. Now depending on what interface you query you'll be hitting different chain nodes.
# docker-compose.yml
services:
  chain:
    image: ghcr.io/foundry-rs/foundry:nightly-0e519ffde8ab5babde7dffa96fca28cfa3608b59
    ports: ["8545:8545"]
    command: ["anvil --host=0.0.0.0 --chain-id=1337 --base-fee=0"]

Search terms

hardhat,node,port,collision,docker,ipv4,ipv6

@tmigone tmigone changed the title hardhat node fails to detect IPv6 port collision with * hardhat node fails to detect IPv6 port collision Feb 18, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Feb 18, 2025
@tmigone
Copy link
Contributor Author

tmigone commented Feb 18, 2025

Just figured out I can use --hostname to bind to 0.0.0.0, which is precisely what we are doing with the anvil node

I'll close the issue since I think it's probably not a bug but a Layer 8 problem 😆

@tmigone tmigone closed this as completed Feb 18, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants