Correctly handle missing layer upload
Because we guarded the error check, nil Upload on the handler was getting through to unexpected branches. This directly handles the missing upload ensuring its set as expected. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
21a69f53b5
commit
c78335a023
1 changed files with 14 additions and 4 deletions
|
@ -53,13 +53,20 @@ func layerUploadDispatcher(ctx *Context, r *http.Request) http.Handler {
|
||||||
|
|
||||||
layers := ctx.services.Layers()
|
layers := ctx.services.Layers()
|
||||||
upload, err := layers.Resume(luh.Name, luh.UUID)
|
upload, err := layers.Resume(luh.Name, luh.UUID)
|
||||||
if err != nil && err != storage.ErrLayerUploadUnknown {
|
if err != nil {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
ctx.log.Errorf("error resolving upload: %v", err)
|
ctx.log.Errorf("error resolving upload: %v", err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
if err == storage.ErrLayerUploadUnknown {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
luh.Errors.Push(v2.ErrorCodeBlobUploadUnknown, err)
|
luh.Errors.Push(v2.ErrorCodeBlobUploadUnknown, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
luh.Errors.Push(v2.ErrorCodeUnknown, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
luh.Upload = upload
|
luh.Upload = upload
|
||||||
|
|
||||||
if state.Offset > 0 {
|
if state.Offset > 0 {
|
||||||
|
@ -68,6 +75,7 @@ func layerUploadDispatcher(ctx *Context, r *http.Request) http.Handler {
|
||||||
// problems. We basically cancel the upload and tell the client to
|
// problems. We basically cancel the upload and tell the client to
|
||||||
// start over.
|
// start over.
|
||||||
if nn, err := upload.Seek(luh.State.Offset, os.SEEK_SET); err != nil {
|
if nn, err := upload.Seek(luh.State.Offset, os.SEEK_SET); err != nil {
|
||||||
|
defer upload.Close()
|
||||||
ctx.log.Infof("error seeking layer upload: %v", err)
|
ctx.log.Infof("error seeking layer upload: %v", err)
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
@ -75,6 +83,7 @@ func layerUploadDispatcher(ctx *Context, r *http.Request) http.Handler {
|
||||||
upload.Cancel()
|
upload.Cancel()
|
||||||
})
|
})
|
||||||
} else if nn != luh.State.Offset {
|
} else if nn != luh.State.Offset {
|
||||||
|
defer upload.Close()
|
||||||
ctx.log.Infof("seek to wrong offest: %d != %d", nn, luh.State.Offset)
|
ctx.log.Infof("seek to wrong offest: %d != %d", nn, luh.State.Offset)
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
@ -129,6 +138,7 @@ func (luh *layerUploadHandler) GetUploadStatus(w http.ResponseWriter, r *http.Re
|
||||||
if luh.Upload == nil {
|
if luh.Upload == nil {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
luh.Errors.Push(v2.ErrorCodeBlobUploadUnknown)
|
luh.Errors.Push(v2.ErrorCodeBlobUploadUnknown)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := luh.layerUploadResponse(w, r); err != nil {
|
if err := luh.layerUploadResponse(w, r); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue