Skip to content

Commit

Permalink
Fix upload session timeout (#294)
Browse files Browse the repository at this point in the history
* Add empty request to avoid session timeout

Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
  • Loading branch information
vbauzys authored Apr 2, 2020
1 parent bc63d3c commit 8bea87b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ NOTES:

BUGS FIXED:
* Fix issue in Queries with vCD 10 version, which do not return network pool or provider VDC[#293](https://github.com/vmware/go-vcloud-director/pull/293)
* Session timeout for media, catalog item upload [#294](https://github.com/vmware/go-vcloud-director/pull/294)

## 2.6.0 (March 13, 2010)

Expand Down
11 changes: 11 additions & 0 deletions govcd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ func newFileUploadRequest(client *Client, requestUrl string, filePart []byte, of
// partDataSize - how much bytes will be uploaded
// uploadDetails - file upload settings and data
func uploadPartFile(client *Client, part []byte, partDataSize int64, uDetails uploadDetails) error {
// Avoids session time out, as the multi part upload is treated as one request
makeEmptyRequest(client)
request, err := newFileUploadRequest(client, uDetails.uploadLink, part, uDetails.uploadedBytes, partDataSize, uDetails.fileSizeToUpload)
if err != nil {
return err
Expand All @@ -178,6 +180,15 @@ func uploadPartFile(client *Client, part []byte, partDataSize int64, uDetails up
return nil
}

// call query for task which are very fast and optimised as UI calls it very often
func makeEmptyRequest(client *Client) {
apiEndpoint := client.VCDHREF
apiEndpoint.Path += "/query?type=task&format=records&page=1&pageSize=5&"

_, _ = client.ExecuteRequest(apiEndpoint.String(), http.MethodGet,
"", "error making empty request: %s", nil, nil)
}

func getUploadLink(files *types.FilesList) (*url.URL, error) {
util.Logger.Printf("[TRACE] getUploadLink - Parsing upload link: %#v\n", files)

Expand Down

0 comments on commit 8bea87b

Please sign in to comment.