Skip to content

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

Merged
Lifeng Lu (lifengl) merged 2 commits into
mainfrom
dev/lifengl/preventTwoTaskWaitingChains
Mar 28, 2022
Merged

Lifeng Lu (lifengl) merged 2 commits into
mainfrom
dev/lifengl/preventTwoTaskWaitingChains

Conversation

@lifengl

@lifengl Lifeng Lu (lifengl) commented Mar 22, 2022 •

Copy link
Copy Markdown
Member

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.

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.
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