Skip to content

Fix infinite loop when failed to find path for volume on Windows - #2066

Merged
shirou merged 3 commits into
shirou:masterfrom
woct0rdho:fix-get-volume-paths
Apr 4, 2026
Merged

Fix infinite loop when failed to find path for volume on Windows#2066
shirou merged 3 commits into
shirou:masterfrom
woct0rdho:fix-get-volume-paths

Conversation

@woct0rdho

@woct0rdho woct0rdho commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

When getVolumePaths returns an error, we should not just continue the for loop. We should skip processMountsForVolume, then update volNameBuf using procFindNextVolumeW. Otherwise it would loop forever.

I discovered this bug when running wandb, which uses gopsutil to collect system info, and there is a virtual CD program on my machine that leaves a stale volume that causes an error in getVolumePaths. It's discussed in #1911 but not really fixed yet.

@StefanoBalzarottiNozomi

StefanoBalzarottiNozomi commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

thanks for the fix, but are you able to add a test to simulate the problem ?

@woct0rdho

woct0rdho commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

I've refactored it to allow inserting custom functions getVolumePathsFn, processMountsForVolumeFn, findNextVolumeFn, then test how many times these functions are called in processVolumeLoopWith.

I'm not very familiar with Go. In Python people would monkey-patch getVolumePaths to test it, but I'm not sure if there is a way to do so in Go.

@shirou shirou left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for your PR. The fix for the infinite loop is a nice catch!

I appreciate you adding the test based on the review feedback. However, the test only verifies the if/else control flow, which is fairly straightforward. I think changing the function signature to 9 arguments just for this test is a bit much.

Sorry for the extra work, but could you revert to your original minimal fix? That's all we need here. Thanks!

This reverts commit a257800.
@woct0rdho

Copy link
Copy Markdown
Contributor Author

Ok I've reverted the test and kept it a minimal change.

@shirou shirou left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you so much!

@shirou
shirou merged commit 0f7fa6a into shirou:master Apr 4, 2026
51 checks passed
@woct0rdho
woct0rdho deleted the fix-get-volume-paths branch April 4, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment