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

Losing thread local change when switching coroutine context #3787

Closed
wanyingd1996 opened this issue Jun 21, 2023 · 0 comments
Closed

Losing thread local change when switching coroutine context #3787

wanyingd1996 opened this issue Jun 21, 2023 · 0 comments
Assignees
Labels

Comments

@wanyingd1996
Copy link
Contributor

CopyableThreadContextElement was created as a way to propagate thread local changes to child coroutine, and we have been relying on this feature to propagate traces(thread local based) for our system. Recently, we ran into issue where the thread local changes was lost when flowOn is used to switch coroutine context. And as I look into the source code of ChannelFlow, I can see when switching to new context, no new CopyableThreadContextElement was created if the dispatcher hasn't changed, so the old thread element was used for the flow execution, and the old thread context element was created at the time when the coroutine context was constructed, so it is holding the thread local created at that time. In our case, trace is lost within the scope of the flow. I have created #3778, and created test repro the issue I ran into, please take a look when you have time, and let me know if there is any concerns for the patch, thanks!

@qwwdfsad qwwdfsad self-assigned this Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants