ZIO 2.0 instrumentation#7980
Conversation
|
|
cefd1ff to
dc24d4f
Compare
ZIO context handling
|
Hi @laurit, what do you think about the following change to this PR: dmytr#2? It seems to be more correct if we store thread's active context when fiber is resumed, and restore it when fiber is suspended. Instead of just restoring the root context. Tests pass, and I've tested this with my test harness - everything still seems to work. |
@dmytr I think it would work. But as the thread executing the fibers probably should not have a context outside of executing the fiber, and when it has, it is probably a context that was inadvertently leaked there, I'd keep the current approach just because it is a bit simpler. Unless you are suspecting that the thread could have a meaningful context outside of executing fibers that must be preserved I wouldn't change it. |
|
Hi @laurit 👋 Seems like I'm a bit late to the party 😅 I think that you are right and in most cases context outside of the fiber wouldn't matter. However I looked into the details of how
|
|
@dmytr Even with netty threads I would assume that the thread that is used for fiber doesn't have a meaningful scope. If it had a meaningful scope it would be in the middle of some other operation and getting borrowed to run the fiber would be strange. |
Summary
ZIO is a popular Scala library for asynchronous and concurrent programming. Its runtime uses green threads (fibers) which breaks instrumentation because context is stored in
ThreadLocalvariable. This PR takes care of synchronizing context between fibers and JVM threads on which they are executed.Notes about implementation
FiberContextis the main piece which handles context synchronization. Implementation was tested on a non-trivial distributed application.