Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
fleetctl: wait for unit creation to prevent spurious 404 errors
Browse files Browse the repository at this point in the history
in testing with coretest, fleetd would get spurious errors while
creating and then reading back units. it is a race that occurs when a
PUT (consistent write to etcd) is immediately followed by a GET
(inconsistent read) to the same unit.

the real fix for this is to make use of etcd indexes everywhere in
fleetd, but unfortunately etcd 0.4.x indexes are broken. as a
workaround, we block in fleetctl waiting for acknowledgement of unit
creation before proceeding to load/start/etc.
  • Loading branch information
Nick Owens committed Aug 5, 2015
1 parent f9ca1be commit 1816c53
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions fleetctl/fleetctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ func createUnit(name string, uf *unit.UnitFile) (*schema.Unit, error) {
// subsequent Jobs are not acted on). An error is also returned if none of the
// above conditions match a given Job.
func lazyCreateUnits(args []string) error {
errchan := make(chan error)
var wg sync.WaitGroup
for _, arg := range args {
// TODO(jonboulle): this loop is getting too unwieldy; factor it out

Expand Down Expand Up @@ -660,7 +662,26 @@ func lazyCreateUnits(args []string) error {
if err != nil {
return err
}

wg.Add(1)
go checkUnitState(name, job.JobStateInactive, sharedFlags.BlockAttempts, os.Stdout, &wg, errchan)
}

go func() {
wg.Wait()
close(errchan)
}()

haserr := false
for msg := range errchan {
stderr("Error waiting on unit creation: %v", msg)
haserr = true
}

if haserr {
return fmt.Errorf("One or more errors creating units")
}

return nil
}

Expand Down

0 comments on commit 1816c53

Please sign in to comment.