[FIX] Rethrow takeVMSnapshot() exception#3546
Conversation
…pshotManagerImpl Fixes: #3518
|
An alternative fix for the NPE would be to modify |
|
I suspect that |
|
Sorry, scratch that last remark. These function only get a boolean return value. No risk of an NPE there. |
|
@blueorangutan package |
|
@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
What do you think, @rhtyd ? Would a null value check in Otherwise, the other null checks could be removed completely, as we would never return a null value. |
|
The only thing I would check is if throwing an exception would cause any snapshot/item in the db to be set in incorrect state, i.e. any cleanup that may be necessary when the method throws the exception. |
|
Packaging result: ✔centos6 ✔centos7 ✔debian. JID-235 |
|
The problem here is that this fairly difficult, as I don't have a reliable way to trigger throwing an exception, in a real life scenario. A test scenario should (roughly) look like this:
Conversely, a positive test should also exist, that does the following:
|
| } catch (Exception e) { | ||
| s_logger.debug("Failed to create vm snapshot: " + vmSnapshotId, e); | ||
| return null; | ||
| throw new CloudRuntimeException("Failed to create vm snapshot: " + vmSnapshotId, e); |
There was a problem hiding this comment.
I think setting the snapshot to a good state should happen here. not sure what it would be, but probably 'Error'.
There was a problem hiding this comment.
ok, we'll have to find out in testing (or bad experience) I can not in good conscience hold this given your answers in the comment, @onitake . Let's be aware in case anything happens to the snapshot functionality
should have marked it request changes
|
@onitake can you add setting the snapshot state before throwing the exception? |
|
There are other sources for exceptions, not just the part that did The NPE was not handled properly anywhere AFAIK, so nothing would properly set an error state. |
|
ok, fair point but than at this point it can also not deal with CloudRuntimeException expecting not snapshot being created in the first place or expect that no error state needs to set at that point. |
|
@DaanHoogland Setting the snapshot state to "Error" would involve something like this: try {
VMSnapshot.State.getStateMachine().transitTo(vmSnapshot, VMSnapshot.Event.OperationFailed, null, _vmSnapshotDao);
} catch (NoTransitionException ex) {
throw new CloudRuntimeException("Cannot transit snapshot to failed state", ex);
}I'm not sure putting this into the exception handler is a good idea. Maybe it would be better to ensure the CloudRuntimeException is accounted for. There should already be code for setting the error state somewhere. |
|
So, after some more digging, I came to the conclusion that there are two major code paths how the snapshot creation can be reached:
|
| } catch (Exception e) { | ||
| s_logger.debug("Failed to create vm snapshot: " + vmSnapshotId, e); | ||
| return null; | ||
| throw new CloudRuntimeException("Failed to create vm snapshot: " + vmSnapshotId, e); |
There was a problem hiding this comment.
ok, we'll have to find out in testing (or bad experience) I can not in good conscience hold this given your answers in the comment, @onitake . Let's be aware in case anything happens to the snapshot functionality
|
please not that this still needs testing! |
|
Smoketests/Travis LGTM, and OK. |
|
@rhtyd is this only going into 4.14? No backport to 4.13? |
|
The PR was opened for master so it will go into 4.14, if you'd want in 4.13 (4.13.1.0 milestone) please send a PR against 4.13 branch @onitake |
|
All right, will do. |
…pache#3546) Fixes NPE, and throws actual exception with the error stacktrace Fixes: apache#3518
Description
This patch changes the behaviour of
VMSnapshotManagerImpl.orchestrateCreateVMSnapshot(Long vmId, Long vmSnapshotId, Boolean quiescevm)to rethrow the exception whentakeVMSnapshot()fails, instead of returning null.If null is returned, this will lead to a NullPointerException in
VMSnapshotManagerImpl.orchestrateCreateVMSnapshot(VmWorkCreateVMSnapshot work)in thesnapshot.getId()call, and causes an incomplete snapshot entry to remain in the database.Fixes: #3518
See there for more details.
Types of changes
Screenshots (if appropriate):
How Has This Been Tested?
This change has not been tested yet.
At this point, it is unknown if it will cause unexpected side effects.