Skip to content

Commit dcae0d3

Browse files
authored
p2p/simulations: fix a deadlock and clean up adapters (#17891)
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.
1 parent f951e23 commit dcae0d3

File tree

9 files changed

+164
-418
lines changed

9 files changed

+164
-418
lines changed

node/node.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,23 @@ func (n *Node) IPCEndpoint() string {
549549

550550
// HTTPEndpoint retrieves the current HTTP endpoint used by the protocol stack.
551551
func (n *Node) HTTPEndpoint() string {
552+
n.lock.Lock()
553+
defer n.lock.Unlock()
554+
555+
if n.httpListener != nil {
556+
return n.httpListener.Addr().String()
557+
}
552558
return n.httpEndpoint
553559
}
554560

555561
// WSEndpoint retrieves the current WS endpoint used by the protocol stack.
556562
func (n *Node) WSEndpoint() string {
563+
n.lock.Lock()
564+
defer n.lock.Unlock()
565+
566+
if n.wsListener != nil {
567+
return n.wsListener.Addr().String()
568+
}
557569
return n.wsEndpoint
558570
}
559571

p2p/simulations/README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ using the devp2p node stack rather than executing `main()`.
6363
The nodes listen for devp2p connections and WebSocket RPC clients on random
6464
localhost ports.
6565

66-
### DockerAdapter
67-
68-
The `DockerAdapter` is similar to the `ExecAdapter` but executes `docker run`
69-
to run the node in a Docker container using a Docker image containing the
70-
simulation binary at `/bin/p2p-node`.
71-
72-
The Docker image is built using `docker build` when the adapter is initialised,
73-
meaning no prior setup is necessary other than having a working Docker client.
74-
75-
Each node listens on the external IP of the container and the default p2p and
76-
RPC ports (`30303` and `8546` respectively).
77-
7866
## Network
7967

8068
A simulation network is created with an ID and default service (which is used

p2p/simulations/adapters/docker.go

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)