Skip to content

Commit 66e676e

Browse files
meafmirailer
authored andcommitted
Fixed timeout issue
1 parent b116b02 commit 66e676e

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

upcloud/client/client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package client
33
import (
44
"bytes"
55
"fmt"
6-
"github.com/blang/semver"
7-
"github.com/hashicorp/go-cleanhttp"
86
"io"
97
"io/ioutil"
108
"net/http"
119
"time"
10+
11+
"github.com/blang/semver"
1212
)
1313

1414
// Constants
@@ -50,6 +50,11 @@ func (c *Client) SetTimeout(timeout time.Duration) {
5050
c.httpClient.Timeout = timeout
5151
}
5252

53+
// GetTimeout returns current timeout
54+
func (c *Client) GetTimeout() time.Duration {
55+
return c.httpClient.Timeout
56+
}
57+
5358
// CreateRequestUrl creates and returns a complete request URL for the specified API location
5459
func (c *Client) CreateRequestUrl(location string) string {
5560
return fmt.Sprintf("%s%s", c.getBaseUrl(), location)

upcloud/service/service.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package service
33
import (
44
"encoding/xml"
55
"fmt"
6+
"time"
7+
68
"github.com/UpCloudLtd/upcloud-go-api/upcloud"
79
"github.com/UpCloudLtd/upcloud-go-api/upcloud/client"
810
"github.com/UpCloudLtd/upcloud-go-api/upcloud/request"
9-
"time"
1011
)
1112

1213
// Service represents the API service. The specified client is used to communicate with the API
@@ -185,12 +186,18 @@ func (s *Service) WaitForServerState(r *request.WaitForServerStateRequest) (*upc
185186

186187
// StartServer starts the specified server
187188
func (s *Service) StartServer(r *request.StartServerRequest) (*upcloud.ServerDetails, error) {
189+
// Save previous timeout
190+
prevTimeout := s.client.GetTimeout()
191+
188192
// Increase the client timeout to match the request timeout
189193
s.client.SetTimeout(r.Timeout)
190194

191195
serverDetails := upcloud.ServerDetails{}
192196
response, err := s.client.PerformPostRequest(s.client.CreateRequestUrl(r.RequestURL()), nil)
193197

198+
// Restore previous timout
199+
s.client.SetTimeout(prevTimeout)
200+
194201
if err != nil {
195202
return nil, parseServiceError(err)
196203
}

0 commit comments

Comments
 (0)