diff --git a/builder/googlecompute/driver_gce.go b/builder/googlecompute/driver_gce.go index b63c293ad..b5c8c62e5 100644 --- a/builder/googlecompute/driver_gce.go +++ b/builder/googlecompute/driver_gce.go @@ -757,13 +757,16 @@ func (d *driverGCE) AddToInstanceMetadata(zone string, name string, metadata map } newErrCh := make(chan error, 1) - go waitForState(newErrCh, "DONE", d.refreshZoneOp(zone, op)) - select { - case err = <-newErrCh: - case <-time.After(time.Second * 30): - err = errors.New("time out while waiting for instance to create") - } + go func() { + err = waitForState(newErrCh, "DONE", d.refreshZoneOp(zone, op)) + + select { + case err = <-newErrCh: + case <-time.After(time.Second * 30): + err = errors.New("time out while waiting for instance to create") + } + }() if err != nil { newErrCh <- err diff --git a/builder/googlecompute/driver_mock.go b/builder/googlecompute/driver_mock.go index cbe89dd76..76b1fcee5 100644 --- a/builder/googlecompute/driver_mock.go +++ b/builder/googlecompute/driver_mock.go @@ -304,7 +304,6 @@ func (d *DriverMock) AddToInstanceMetadata(zone string, name string, metadata ma if resultCh == nil { ch := make(chan error) close(ch) - resultCh = ch } return nil