Skip to content

Commit

Permalink
Improve error handling when spinning up homeservers (#434)
Browse files Browse the repository at this point in the history
* Stop starting homeservers on first fail
* waitForContainer: remove unused `err` variable
* waitForContainer: skip /versions check on failed server
  • Loading branch information
richvdh authored Aug 11, 2022
1 parent aed418c commit 4658bfb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions internal/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ func (d *Builder) construct(bprint b.Blueprint) (errs []error) {
}); delErr != nil {
d.log("%s: failed to remove container which failed to deploy: %s", res.contextStr, delErr)
}
// there is little point continuing to set up the remaining homeservers at this point
return
}
// kill the container
defer func(r result) {
Expand Down
11 changes: 4 additions & 7 deletions internal/docker/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func deployImage(
// Ensure that the homeservers under test can contact the host, so they can
// interact with a complement-controlled test server.
// Note: this feature of docker landed in Docker 20.10,
// see https://github.com/moby/moby/pull/40007
// see https://github.com/moby/moby/pull/40007
extraHosts = []string{"host.docker.internal:host-gateway"}
}

Expand Down Expand Up @@ -423,17 +423,15 @@ func waitForPorts(ctx context.Context, docker *client.Client, containerID string
}

// Waits until a homeserver deployment is ready to serve requests.
func waitForContainer(ctx context.Context, docker *client.Client, hsDep *HomeserverDeployment, stopTime time.Time) (iterCount int, err error) {
var lastErr error = nil

func waitForContainer(ctx context.Context, docker *client.Client, hsDep *HomeserverDeployment, stopTime time.Time) (iterCount int, lastErr error) {
iterCount = 0

// If the container has a healthcheck, wait for it first
for {
iterCount += 1
if time.Now().After(stopTime) {
lastErr = fmt.Errorf("timed out checking for homeserver to be up: %s", lastErr)
break
return
}
inspect, err := docker.ContainerInspect(ctx, hsDep.ContainerID)
if err != nil {
Expand Down Expand Up @@ -477,8 +475,7 @@ func waitForContainer(ctx context.Context, docker *client.Client, hsDep *Homeser
lastErr = nil
break
}

return iterCount, lastErr
return
}

// RoundTripper is a round tripper that maps https://hs1 to the federation port of the container
Expand Down

0 comments on commit 4658bfb

Please sign in to comment.