Skip to content
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 hangs when file path is provided with wildcard without recurse flag #2800

Merged
merged 8 commits into from
Mar 15, 2024

Conversation

shaopeng-gh
Copy link
Collaborator

  • BUG: Resolve hangs when a file path is provided with wildcard but without -r (recurse) flag during the multithreaded analysis file enumeration phase.

…hout `-r` (recurse) flag during multithreaded analysis file enumeration phase.

filesToProcessChannel.Writer.Complete();
directoryEnumerationTask = Task.CompletedTask;
directoryEnumerationTask = Task.Run(() =>
Copy link
Member

@michaelcfanning michaelcfanning Mar 12, 2024

Choose a reason for hiding this comment

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

directoryEnumerationTask

where is the test for this? you haven't provided an explanation of what the problem was or explained the fix in any way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

where is the test for this --- working on it next. Want to give an early update that the issue has been found, or else will need Scott's view since he made this change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

@shaopeng-gh shaopeng-gh marked this pull request as draft March 12, 2024 19:28
ReleaseHistory.md Outdated Show resolved Hide resolved
Copy link

@stacywray stacywray left a comment

Choose a reason for hiding this comment

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

Requested changes.

ReleaseHistory.md Outdated Show resolved Hide resolved
@@ -35,5 +36,64 @@ public void Multitool_LaunchesAndRunsSuccessfully()
process.ExitCode.Should().Be(0);
}
}

#if DEBUG
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to test the analyze command hang, in sdk we only have analyze-test which is also wrapped under #if DEBUG so my test will also need to be wrapped under it.
I have tested .\BuildAndTest.cmd -Configuration Debug will all pass.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the 12k files were a red herring, and it would have hung on one file. If that's true, then I don't think we shouldn't take a 12k/5 sec UT when an instantaenous one will do.

What do you think?

Also: did you go back and verify that the UT hangs on the unmodified code? I think that's important for this tes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was confused. Shaopeng educated me offline. Issue is we fill the channel without yielding our thread. So you really do need 10k+ files, because that's the channel size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also: did you go back and verify that the UT hangs on the unmodified code? I think that's important for this tes.
----- yes, undo the fix and leave test can repro and have the error in the screenshot in the other comment.

as talk in IM we need 10241 files.

Will work on the change you recommended in IM.


using (var process = Process.Start(startInfo))
{
var timer = new System.Timers.Timer(30000); // 30 seconds.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

with fix, it will pass, it will only runs within 5 seconds so will not affect testing run total time:
image

before fix, it will fail and the message will be like below for dev:
image

@@ -87,27 +87,24 @@ private IEnumerable<IEnumeratedArtifact> EnumeratedArtifacts()

Task directoryEnumerationTask;

if (this.recurse)
directoryEnumerationTask = Task.Run(() =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The issue and fix is simple, in the recurse false code path we missed to use Task.Run to run the file enumeration operation asynchronously on the separate thread.
Now we merged in a same code block so both
recurse true and false will have it.

@shaopeng-gh shaopeng-gh marked this pull request as ready for review March 14, 2024 07:56

Directory.CreateDirectory(directoryPath);

for (int i = 1; i <= 12000; i++)
Copy link
Contributor

Choose a reason for hiding this comment

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

Soft-recommend (do not require) using internalsvisibleto to couple this parameter to the channel size.
ChannelCapacity.

Signing off.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated to use the ChannelCapacity + 1.
Tried a few times, only need + 1 to repro.

@scottoneil-ms scottoneil-ms merged commit a61cf94 into main Mar 15, 2024
8 checks passed
@shaopeng-gh shaopeng-gh deleted the users/shaopeng-gh/fixfileloop branch March 15, 2024 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants