-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix when rbdVol is nil, panic occurred #4002
Conversation
Do you have steps to reproduce this problem? It would be good to have a test case, or at least be able to validate the fix. |
@@ -1078,7 +1078,9 @@ func (cs *ControllerServer) CreateSnapshot( | |||
|
|||
// Fetch source volume information | |||
rbdVol, err := GenVolFromVolID(ctx, req.GetSourceVolumeId(), cr, req.GetSecrets()) | |||
defer rbdVol.Destroy() | |||
if rbdVol != nil { | |||
defer rbdVol.Destroy() |
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.
this could be moved after if err != nil
, no need to check if rbdVol != nil
in that case.
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.
Thanks for the contribution,
Please fix your commit message by referring to https://github.com/ceph/ceph-csi/blob/b1d1d3bf75b8becb427ec494dd6449f7b5bce115/docs/development-guide.md#commit-messages .
Hi @huangzynn , in order to fix the commitlint issue, please make these changes:
Many thanks! |
So, by reading the screenshots, is it correct to say that the problem can be triggered when creating a VolumeSnapshot of a non-existing PVC? |
|
internal/rbd/controllerserver.go
Outdated
@@ -1092,6 +1091,7 @@ func (cs *ControllerServer) CreateSnapshot( | |||
|
|||
return nil, err | |||
} | |||
defer rbdVol.Destroy() |
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.
This can cause a cleanup problem as rbdVol is returned even in case of error. IMO moving this to line 1081 with a check for nil is okay.
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.
That's what I thought from the beginning
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.
rbdVol
should never be returned in a case of an error. Either err != nil
or rbdVol != nil
. The additional if-statement should be useless, and in effect is the same as having the defer
below the error handling. It adds a bit of complexity, and makes me wonder if rbdVol == nil
should not be handled further down in the function as well?
4bfae38
to
f61add6
Compare
@huangzynn as suggested here https://github.com/ceph/ceph-csi/blob/b1d1d3bf75b8becb427ec494dd6449f7b5bce115/docs/development-guide.md#commit-messages you need to update the commit to fix the commitlint CI problem. @nixpanic posted a sample for you above. you are missing |
add if rbdVol != nil defer rbdVol.Destroy() Signed-off-by: huangzy <huangzynn@outlook.com>
It seems not trivial to reproduce this, when I try, I get the following
Maybe the PCV needs to exist to pass the snapshot-controller check, and get deleted before Ceph-CSI acts on it? |
What is your snapshot controller version? |
My cluster has v6.2.1... not sure if there is a big difference between those. |
@huangzynn can you please provide the below details from this cluster.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in two weeks if no further activity occurs. Thank you for your contributions. |
This pull request has been automatically closed due to inactivity. Please re-open if these changes are still required. |
When rbdVol is nil, panic occurred
add if rbdVol != nil