Skip to content

Commit 269ebd6

Browse files
committed
Don't delete failed upload caused by rate limit
If the upload failed due to rate limit (HTTP 498), there is no need to delete the failed object, because it will definitely not in Swift. The delete itself might cause an additional rate limit response. This fix only applies to non large object uplaods.
1 parent e144b1b commit 269ebd6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/objects/file.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,16 @@ func (f File) uploadNormalObject(body io.Reader, sourceState FileState, hdr swif
157157

158158
util.Log(util.LogError, "PUT %s/%s failed: %s", containerName, objectName, err.Error())
159159

160-
//delete potentially incomplete upload
161-
err = f.Job.Target.Connection.ObjectDelete(containerName, objectName)
162-
if err != nil {
163-
util.Log(util.LogError, "DELETE %s/%s failed: %s", containerName, objectName, err.Error())
160+
if serr, ok := err.(*swift.Error); ok {
161+
//upload failed due to rate limit, object is definitely not uploaded
162+
//prevent additional rate limit caused by an unnecessary delete request
163+
if serr.StatusCode != 498 {
164+
//delete potentially incomplete upload
165+
err = f.Job.Target.Connection.ObjectDelete(containerName, objectName)
166+
if err != nil {
167+
util.Log(util.LogError, "DELETE %s/%s failed: %s", containerName, objectName, err.Error())
168+
}
169+
}
164170
}
165171

166172
return false

0 commit comments

Comments
 (0)