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 deadlock in ProcessUtil #1457

Merged
merged 4 commits into from
Dec 19, 2023
Merged

Conversation

karolz-ms
Copy link
Member

@karolz-ms karolz-ms commented Dec 19, 2023

Fixes #1420

Microsoft Reviewers: Open in CodeFlow

@JamesNK
Copy link
Member

JamesNK commented Dec 19, 2023

Unit test?

@karolz-ms
Copy link
Member Author

Unit test?

Honestly I am not sure what kind of unit test would make sense for this change. Any suggestions?

@JamesNK
Copy link
Member

JamesNK commented Dec 19, 2023

Is it possible to re-create the deadlock in a test? If so, have a test of that scenario that now passes.

@BrennanConroy
Copy link
Member

Is it possible to re-create the deadlock in a test?

Not without private reflection into the internals of Process and adding hooks to our callbacks just for testing.

@JamesNK
Copy link
Member

JamesNK commented Dec 19, 2023

So you're saying there's a chance...

ok, nvm

@BrennanConroy
Copy link
Member

Yes 😆

@karolz-ms karolz-ms marked this pull request as draft December 19, 2023 01:48
@karolz-ms
Copy link
Member Author

Since here we only care about startup activities to be completed before anything else happens, I can think of a better fix, using manual reset event. Stay tuned...

@JamesNK
Copy link
Member

JamesNK commented Dec 19, 2023

Is the problem in #1420 that HasExited can cause the process to check whether the process has exited, realize it has, and then run the Exited event inline?

What is the purpose of checking HasExited in the OutputDataReceived/ErrorDataReceived events? Could we change it so the Exited event sets a private bool _hasExited to true, and then OutputDataReceived/ErrorDataReceived checks _hasExited to see whether an exit has been triggered? The field wouldn't be quite as up to date as HasExited, but does that matter?

This allows multiple event handlers to run concurrently
@karolz-ms karolz-ms marked this pull request as ready for review December 19, 2023 02:06
@karolz-ms
Copy link
Member Author

@JamesNK I think my second attempt is both more robust and easier to understand from the intention perspective. LMK what you think!

@JamesNK
Copy link
Member

JamesNK commented Dec 19, 2023

@JamesNK I think my second attempt is both more robust and easier to understand from the intention perspective. LMK what you think!

I like it more. It needs some comments explaining why it works the way it does.

@karolz-ms
Copy link
Member Author

Thanks @JamesNK!

@karolz-ms karolz-ms merged commit 215c68b into main Dec 19, 2023
8 checks passed
@karolz-ms karolz-ms deleted the dev/karolz/process-util-deadlock branch December 19, 2023 17:10
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rare deadlock when processes exit
3 participants