-
Notifications
You must be signed in to change notification settings - Fork 95
Fix error handling when rolling back volume creation #617
Conversation
errRm := d.ops.Remove(r.Name, nil) | ||
if errRm != nil { | ||
log.WithFields(log.Fields{"name": r.Name, "error": errRm}).Error("Remove volume failed ") | ||
return volume.Response{Err: errRm.Error()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its preferable that the error returned on a create error is the create error itself vs. a remove error (which is confusing to the user, when they issued a create command). OTOH, how did this cause the empty response from docker to the docker command line. Logging the error is fine but the original error should be returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its preferable that the error returned on a create error is the create error itself vs. a remove error (which is confusing to the user, when they issued a create command).
Agree.
OTOH, how did this cause the empty response from docker to the docker command line.
err was being reassigned to nil inside the rollback block after the attach error, and at the end we would return the volume response with an error nil since we didn't got any errors from the rollback operations. Which if we had, in any case we would return from there.
Tests in plugin.go:
line 248 //dev, err := d.ops.Attach(r.Name, nil)
line 249 err = fmt.Errorf("STUB")
line 250 dev := []byte("an")
Without the patch:
root@vsc01:/tmp/docker-volume-vsphere# docker volume create -d vmdk --name vol$$ -o size=1gb
Error response from daemon: create vol25407: Post http://%2Frun%2Fdocker%2Fplugins%2Fvmdk.sock/VolumeDriver.Create: http: ContentLength=78 with Body length 0
in log:
2016-10-08 21:32:38.880136128 +0100 WEST [INFO] Attaching volume and creating filesystem fstype=ext4 name=vol25407
2016-10-08 21:32:38.880268068 +0100 WEST [ERROR] Attach volume failed, removing the volume error=STUB name=vol25407
With the patch:
root@vsc01:/tmp/docker-volume-vsphere# docker volume create -d vmdk --name vol$$ -o size=1gb
Error response from daemon: create vol25407: VolumeDriver.Create: STUB
in log:
2016-10-08 21:37:47.746007178 +0100 WEST [INFO] Attaching volume and creating filesystem name=vol25407 fstype=ext4
2016-10-08 21:37:47.746070732 +0100 WEST [ERROR] Attach volume failed, removing the volume name=vol25407 error=STUB
a3c2595
to
2512516
Compare
@govint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for fixing this.
errRm := d.ops.Remove(r.Name, nil) | ||
if errRm != nil { | ||
log.WithFields(log.Fields{"name": r.Name, "error": errRm}).Error("Remove volume failed ") | ||
return volume.Response{Err: errRm.Error()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but the err* names should be consistent IMO.
return volume.Response{Err: err.Error()} | ||
errRm := d.ops.Remove(r.Name, nil) | ||
if errRm != nil { | ||
log.WithFields(log.Fields{"name": r.Name, "error": errRm}).Error("Remove volume failed ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning(). Failed to remove here is not necessarily a big issue I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And about other operations in rollback? Should we also log with warning? IMO those are subsequent errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think errors on rollback are generally warnings - like it's helpful to warn if something we expected to complete failed, but it does not impact success/failure of the actual operation requested. We can silently ignore but I am generally not comfortable with silent failures.
if err != nil { | ||
log.WithFields(log.Fields{"name": r.Name, "error": err}).Error("Detach volume failed ") | ||
return volume.Response{Err: err.Error()} | ||
errDetach := d.ops.Detach(r.Name, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not it be errInGetPath , following the pattern of err names ?
if err != nil { | ||
log.WithFields(log.Fields{"name": r.Name, "error": err}).Error("Detach volume failed ") | ||
return volume.Response{Err: err.Error()} | ||
errDetach := d.ops.Detach(r.Name, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errMkfs
2512516
to
f70febc
Compare
@msterin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A (minor) request to separate detach/remove in a function instead of copy-paste. Given it's a few lines - not a big deal. so approving.
if err != nil { | ||
log.WithFields(log.Fields{"name": r.Name, "error": err}).Error("Detach volume failed ") | ||
return volume.Response{Err: err.Error()} | ||
"error": errMkfs}).Error("Create filesystem failed, removing the volume ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like detach/remove has to be separate in a function instead of copy-paste.
@msterin |
@brunotm - for this PR it's not a problem, I am just generally sensitive to copy-n-paste :-). |
* master: (25 commits) Update new ESX IP added forgotten .so file Install sqlite3 py libs on ESX and load for Python2 Added py code and binaries for sqlite3 python libs Update drone security Removed accidental .pyc files Handle byte to string conversions for status command. Auth configuration and operation admission check (Auth.liping) (vmware-archive#603) Revert "Cli auth.liping" Cli auth.liping (vmware-archive#640) Handle missing or invalid fs type on mount. (vmware-archive#639) Updated Admin CLI commands to support tenants. (vmware-archive#620) Workaround older versions of e2fsprogs (vmware-archive#631) Add auth proposal Made handing of missing metafile less harsh. (vmware-archive#627) Fixed ACLs in payload bin dir (vmware-archive#624) Fixed error handling for set command. (vmware-archive#610) Use new error variables when rolling back volume creation to avoid nil reassignment. (vmware-archive#617) Change wording Fix broken link ...
Fixes #616