-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
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!