@@ -134,10 +134,9 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error
134
134
135
135
cstart := time .Now ()
136
136
glog .Infof ("libmachine.API.Create for %q (driver=%q)" , cfg .Name , cfg .Driver )
137
- if err := api .Create (h ); err != nil {
138
- // Wait for all the logs to reach the client
139
- time .Sleep (2 * time .Second )
140
- return nil , errors .Wrap (err , "create" )
137
+ // Allow two minutes to create host before failing fast
138
+ if err := timedCreateHost (h , api , 2 * time .Minute ); err != nil {
139
+ return nil , errors .Wrap (err , "creating host" )
141
140
}
142
141
glog .Infof ("libmachine.API.Create for %q took %s" , cfg .Name , time .Since (cstart ))
143
142
@@ -151,6 +150,33 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error
151
150
return h , nil
152
151
}
153
152
153
+ func timedCreateHost (h * host.Host , api libmachine.API , t time.Duration ) error {
154
+ timeout := make (chan bool , 1 )
155
+ go func () {
156
+ time .Sleep (t )
157
+ timeout <- true
158
+ }()
159
+
160
+ createFinished := make (chan bool , 1 )
161
+ var err error
162
+ go func () {
163
+ err = api .Create (h )
164
+ createFinished <- true
165
+ }()
166
+
167
+ select {
168
+ case <- createFinished :
169
+ if err != nil {
170
+ // Wait for all the logs to reach the client
171
+ time .Sleep (2 * time .Second )
172
+ return errors .Wrap (err , "create" )
173
+ }
174
+ return nil
175
+ case <- timeout :
176
+ return fmt .Errorf ("create host timed out in %f seconds" , t .Seconds ())
177
+ }
178
+ }
179
+
154
180
// postStart are functions shared between startHost and fixHost
155
181
func postStartSetup (h * host.Host , mc config.MachineConfig ) error {
156
182
glog .Infof ("post-start starting for %q (driver=%q)" , h .Name , h .DriverName )
0 commit comments