Skip to content
Snippets Groups Projects
Commit 8bb0718c authored by Pea Nut's avatar Pea Nut Committed by jkito
Browse files

Improve error handling finding port of helper backend on Mac

parent 8df91ac6
Branches
No related tags found
1 merge request!186Improve error handling
......@@ -18,6 +18,7 @@ package launcher
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
......@@ -41,13 +42,13 @@ type Launcher struct {
const initialHelperPort = 7171
func probeHelperPort(port int) int {
func probeHelperPort(port int) (int, error) {
// this should be enough for a local reply
timeout := time.Duration(500 * time.Millisecond)
c := http.Client{Timeout: timeout}
for {
if smellsLikeOurHelperSpirit(port, &c) {
return port
return port, nil
}
port++
/* we could go until 65k, but there's really no need */
......@@ -55,7 +56,7 @@ func probeHelperPort(port int) int {
break
}
}
return 0
return -1, errors.New("Could not find port of helper backend")
}
func smellsLikeOurHelperSpirit(port int, c *http.Client) bool {
......@@ -93,7 +94,10 @@ func smellsLikeOurHelperSpirit(port int, c *http.Client) bool {
}
func NewLauncher() (*Launcher, error) {
helperPort := probeHelperPort(initialHelperPort)
helperPort, err := probeHelperPort(initialHelperPort)
if err != nil {
return nil, err
}
helperAddr := "http://localhost:" + strconv.Itoa(helperPort)
return &Launcher{helperAddr: helperAddr, Failed: false}, nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment