Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/csi/recover/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (r *FuseRecover) recoverBrokenMount(point mountinfo.MountPoint) (err error)

// Info: Attempting recovery action
glog.V(3).Infof("FuseRecovery: attempting bind mount, source=%s mountPath=%s options=%v", point.SourcePath, point.MountPath, mountOption)
if err := r.Mount(point.SourcePath, point.MountPath, "none", mountOption); err != nil {
// Warning: Mount failure is recoverable - will retry on next cycle
if err = r.Mount(point.SourcePath, point.MountPath, "none", mountOption); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this change correctly fixes the shadowing issue by using assignment (=) instead of a short variable declaration (:=), the use of named return parameters (like err in this function signature) is generally discouraged in Go unless they provide significant documentation value. In this case, the named return directly contributed to the bug. For better maintainability and to prevent similar shadowing issues in the future, consider removing the named return parameter from the function signature and using explicit return err or return nil statements.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "Mount failure is recoverable - will retry on next cycle" no longer matches the new behavior. After this fix, the error propagates to doRecover, which records FuseRecoverFailed and returns — the mount does not retry on the next cycle for this particular broken mount point. Consider updating to something like "Mount failure propagated to caller for event recording".

// Warning: Mount failure is propagated to caller, which records FuseRecoverFailed event
glog.Warningf("FuseRecovery: bind mount failed, mountPath=%s source=%s error=%v", point.MountPath, point.SourcePath, err)
}
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/csi/recover/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ var _ = Describe("FuseRecover", func() {
})

Context("when mount fails", func() {
It("should return without error but log the failure", func() {
It("should return the mount error", func() {
fakeMounter := &mount.FakeMounter{}
r := FuseRecover{SafeFormatAndMount: mount.SafeFormatAndMount{
Interface: fakeMounter,
Expand All @@ -394,7 +394,7 @@ var _ = Describe("FuseRecover", func() {
defer patch1.Reset()

err := r.recoverBrokenMount(point)
Expect(err).NotTo(HaveOccurred())
Expect(err).To(HaveOccurred())
})
})
})
Expand Down