Clean blob uploads when clients interrupts uploading, closes #225

This commit is contained in:
Petu Eusebiu
2021-09-27 17:32:53 +03:00
committed by Ramkumar Chinchani
parent d69ee3f562
commit 20f4051446
2 changed files with 256 additions and 0 deletions
+16
View File
@@ -904,6 +904,14 @@ func (rh *RouteHandler) PatchBlobUpload(w http.ResponseWriter, r *http.Request)
if err != nil {
switch err {
case io.ErrUnexpectedEOF:
rh.c.Log.Warn().Msg("received unexpected EOF, removing .uploads/ files")
if err = is.DeleteBlobUpload(name, sessionID); err != nil {
rh.c.Log.Error().Err(err).Msgf("couldn't remove blobUpload %s in repo %s", sessionID, name)
}
w.WriteHeader(http.StatusInternalServerError)
case errors.ErrBadUploadRange:
WriteJSON(w, http.StatusRequestedRangeNotSatisfiable,
NewErrorList(NewError(BLOB_UPLOAD_INVALID, map[string]string{"session_id": sessionID})))
@@ -1009,6 +1017,14 @@ func (rh *RouteHandler) UpdateBlobUpload(w http.ResponseWriter, r *http.Request)
_, err = is.PutBlobChunk(name, sessionID, from, to, r.Body)
if err != nil {
switch err {
case io.ErrUnexpectedEOF:
rh.c.Log.Warn().Msg("received unexpected EOF, removing .uploads/ files")
if err = is.DeleteBlobUpload(name, sessionID); err != nil {
rh.c.Log.Error().Err(err).Msgf("couldn't remove blobUpload %s in repo %s", sessionID, name)
}
w.WriteHeader(http.StatusInternalServerError)
case errors.ErrBadUploadRange:
WriteJSON(w, http.StatusBadRequest,
NewErrorList(NewError(BLOB_UPLOAD_INVALID, map[string]string{"session_id": sessionID})))