Skip to content

Commit

Permalink
p2p/simulations: fix a deadlock and clean up adapters (#17891)
Browse files Browse the repository at this point in the history
This fixes a rare deadlock with the inproc adapter:

- A node is stopped, which acquires Network.lock.
- The protocol code being simulated (swarm/network in my case)
  waits for its goroutines to shut down.
- One of those goroutines calls into the simulation to add a peer,
  which waits for Network.lock.

The fix for the deadlock is really simple, just release the lock
before stopping the simulation node.

Other changes in this PR clean up the exec adapter so it reports
node startup errors better and remove the docker adapter because
it just adds overhead.

In the exec adapter, node information is now posted to a one-shot
server. This avoids log parsing and allows reporting startup
errors to the simulation host.

A small change in package node was needed because simulation
nodes use port zero. Node.{HTTP,WS}Endpoint now return the live
endpoints after startup by checking the TCP listener.
  • Loading branch information
fjl authored Oct 11, 2018
1 parent f951e23 commit dcae0d3
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 418 deletions.
12 changes: 12 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,23 @@ func (n *Node) IPCEndpoint() string {

// HTTPEndpoint retrieves the current HTTP endpoint used by the protocol stack.
func (n *Node) HTTPEndpoint() string {
n.lock.Lock()
defer n.lock.Unlock()

if n.httpListener != nil {
return n.httpListener.Addr().String()
}
return n.httpEndpoint
}

// WSEndpoint retrieves the current WS endpoint used by the protocol stack.
func (n *Node) WSEndpoint() string {
n.lock.Lock()
defer n.lock.Unlock()

if n.wsListener != nil {
return n.wsListener.Addr().String()
}
return n.wsEndpoint
}

Expand Down
12 changes: 0 additions & 12 deletions p2p/simulations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ using the devp2p node stack rather than executing `main()`.
The nodes listen for devp2p connections and WebSocket RPC clients on random
localhost ports.

### DockerAdapter

The `DockerAdapter` is similar to the `ExecAdapter` but executes `docker run`
to run the node in a Docker container using a Docker image containing the
simulation binary at `/bin/p2p-node`.

The Docker image is built using `docker build` when the adapter is initialised,
meaning no prior setup is necessary other than having a working Docker client.

Each node listens on the external IP of the container and the default p2p and
RPC ports (`30303` and `8546` respectively).

## Network

A simulation network is created with an ID and default service (which is used
Expand Down
190 changes: 0 additions & 190 deletions p2p/simulations/adapters/docker.go

This file was deleted.

Loading

0 comments on commit dcae0d3

Please sign in to comment.