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

Add ability to inject context elements into GlobalScope #1696

Closed
wants to merge 3 commits into from
Closed

Add ability to inject context elements into GlobalScope #1696

wants to merge 3 commits into from

Conversation

frost13it
Copy link

See motivation in #985.

To work reliably, ThreadContextElements need to be contained in a context of each coroutine that uses them, until merge of #1577.

This PR implements an alternative solution proposed by @elizarov: to give libraries an ability to inject elements into the context of GlobalScope.

Note that it does not solve the issue with suspend fun main.

@elizarov
Copy link
Contributor

Unfortunately, solutions based on ServiceLoader (even fast implementation of one) are known to be problematic in Android ecosystem. See the recent hacks that were introduced to make sure that Main dispatcher impl if loaded without service loader on Android. We'll have the same problem with GlobalScope.

If the problem we are solving only relevant for SLFJ4 mapped diagnostic context? If so, could be just provide MDC-specific EmptyGlobalScope in that library only?

@frost13it
Copy link
Author

If the problem we are solving only relevant for SLFJ4 mapped diagnostic context? If so, could be just provide MDC-specific EmptyGlobalScope in that library only?

@elizarov, my use case explained in #985 (comment), so hard-coding MDC support this way won't be suitable for me.
Is there a chance that #1577 will be merged eventually or it will be possible to access current coroutine's context via a ThreadLocal?

@elizarov
Copy link
Contributor

We'll get back to #1577. There are chances we can make it work.

@frost13it
Copy link
Author

It would be great!

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.

None yet

2 participants