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

Prevent creating two task waiting chains when joins AsyncLazy. #999

Merged
merged 2 commits into from
Mar 28, 2022

Conversation

lifengl
Copy link
Member

@lifengl lifengl commented Mar 22, 2022

Prevent creating two task waiting chains when AsyncLazy.GetValueAsync is called. Especially when a cancellation token is being used, we don't need register cancellation token twice. A single task waiting chain would make dump analysis simply (otherwise, it is hard to link the JTF join chain and task waiting chain together.)

Note: this change will help to investigate some issues like excessive amount of tasks waiting for AsyncLazy. Because the current code chains JTF and task waiting separately, it is much harder to connect the JTF and waiting task together. When there are huge amount of waiting tasks, this code would make them doubled. With this change, it will keep a single task waiting chain to make it easier to investigate. Also, when the cancellation token can be cancelled, we will only register one callback instead of two.

@lifengl lifengl requested a review from AArnott March 22, 2022 22:09
We set this.joinableTask to null at the end of the JTF task spinned off here, so value.IsCompleted means that this.joinableTask to be null. Based on that, we can cut all duplicated condition checks to keep it as simple as possible.
@lifengl lifengl enabled auto-merge March 28, 2022 21:55
@lifengl lifengl merged commit a6365a4 into main Mar 28, 2022
@lifengl lifengl deleted the dev/lifengl/preventTwoTaskWaitingChains branch March 28, 2022 22:19
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.

2 participants