aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/simulations/adapters/exec.go
diff options
context:
space:
mode:
authorIvan Daniluk <ivan.daniluk@gmail.com>2018-05-08 23:05:27 +0800
committerFelix Lange <fjl@users.noreply.github.com>2018-05-08 23:05:27 +0800
commitc4a4613d9504db43a26a3c79dda8bf6be0d1237a (patch)
treea9bb552bddbb3fe3ecc795768b376f5b99104e16 /p2p/simulations/adapters/exec.go
parentfedae9501582cb64c850def557b1fc3742d892dc (diff)
downloaddexon-c4a4613d9504db43a26a3c79dda8bf6be0d1237a.tar.gz
dexon-c4a4613d9504db43a26a3c79dda8bf6be0d1237a.tar.zst
dexon-c4a4613d9504db43a26a3c79dda8bf6be0d1237a.zip
p2p/simulations/adapters: fix websocket log line parsing in exec adapter (#16667)
Diffstat (limited to 'p2p/simulations/adapters/exec.go')
-rw-r--r--p2p/simulations/adapters/exec.go26
1 files changed, 3 insertions, 23 deletions
diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go
index a566fb27d..f381c1159 100644
--- a/p2p/simulations/adapters/exec.go
+++ b/p2p/simulations/adapters/exec.go
@@ -17,7 +17,6 @@
package adapters
import (
- "bufio"
"context"
"crypto/ecdsa"
"encoding/json"
@@ -29,7 +28,6 @@ import (
"os/exec"
"os/signal"
"path/filepath"
- "regexp"
"strings"
"sync"
"syscall"
@@ -150,10 +148,6 @@ func (n *ExecNode) Client() (*rpc.Client, error) {
return n.client, nil
}
-// wsAddrPattern is a regex used to read the WebSocket address from the node's
-// log
-var wsAddrPattern = regexp.MustCompile(`ws://[\d.:]+`)
-
// Start exec's the node passing the ID and service as command line arguments
// and the node config encoded as JSON in the _P2P_NODE_CONFIG environment
// variable
@@ -196,23 +190,9 @@ func (n *ExecNode) Start(snapshots map[string][]byte) (err error) {
n.Cmd = cmd
// read the WebSocket address from the stderr logs
- var wsAddr string
- wsAddrC := make(chan string)
- go func() {
- s := bufio.NewScanner(stderrR)
- for s.Scan() {
- if strings.Contains(s.Text(), "WebSocket endpoint opened:") {
- wsAddrC <- wsAddrPattern.FindString(s.Text())
- }
- }
- }()
- select {
- case wsAddr = <-wsAddrC:
- if wsAddr == "" {
- return errors.New("failed to read WebSocket address from stderr")
- }
- case <-time.After(10 * time.Second):
- return errors.New("timed out waiting for WebSocket address on stderr")
+ wsAddr, err := findWSAddr(stderrR, 10*time.Second)
+ if err != nil {
+ return fmt.Errorf("error getting WebSocket address: %s", err)
}
// create the RPC client and load the node info