@@ -222,13 +222,20 @@ func (s *Service) StartServer(r *request.StartServerRequest) (*upcloud.ServerDet
222222
223223// StopServer stops the specified server
224224func (s * Service ) StopServer (r * request.StopServerRequest ) (* upcloud.ServerDetails , error ) {
225+ // Save previous timeout
226+ prevTimeout := s .client .GetTimeout ()
227+
225228 // Increase the client timeout to match the request timeout
226- s .client .SetTimeout (r .Timeout )
229+ // Allow ten seconds to give the API a chance to respond with an error
230+ s .client .SetTimeout (r .Timeout + 10 * time .Second )
227231
228232 serverDetails := upcloud.ServerDetails {}
229233 requestBody , _ := json .Marshal (r )
230234 response , err := s .client .PerformJSONPostRequest (s .client .CreateRequestURL (r .RequestURL ()), requestBody )
231235
236+ // Restore previous timeout
237+ s .client .SetTimeout (prevTimeout )
238+
232239 if err != nil {
233240 return nil , parseJSONServiceError (err )
234241 }
@@ -240,13 +247,20 @@ func (s *Service) StopServer(r *request.StopServerRequest) (*upcloud.ServerDetai
240247
241248// RestartServer restarts the specified server
242249func (s * Service ) RestartServer (r * request.RestartServerRequest ) (* upcloud.ServerDetails , error ) {
250+ // Save previous timeout
251+ prevTimeout := s .client .GetTimeout ()
252+
243253 // Increase the client timeout to match the request timeout
244- s .client .SetTimeout (r .Timeout )
254+ // Allow ten seconds to give the API a chance to respond with an error
255+ s .client .SetTimeout (r .Timeout + 10 * time .Second )
245256
246257 serverDetails := upcloud.ServerDetails {}
247258 requestBody , _ := json .Marshal (r )
248259 response , err := s .client .PerformJSONPostRequest (s .client .CreateRequestURL (r .RequestURL ()), requestBody )
249260
261+ // Restore previous timeout
262+ s .client .SetTimeout (prevTimeout )
263+
250264 if err != nil {
251265 return nil , parseJSONServiceError (err )
252266 }
0 commit comments