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

Cancel current Job on RejectedExecutionException #2012

Merged
merged 11 commits into from Oct 9, 2020
Merged

Conversation

elizarov
Copy link
Contributor

@elizarov elizarov commented May 12, 2020

When the Executor that was used with Executor.asCoroutineDispatcher() extension rejects submitted task, it means that it had reached its capacity and so the executing current Job should be cancelled to terminate it as soon as possible. This way RejectedExecutionException works as a rate-limiter just like it serves this purpose in executor-based Java code.

NOTE: This PR changes internal coroutines API for Delay interface which some 3rd part code might be using, so it should be merged only in the major release.

Fixes #2003

kotlinx-coroutines-core/jvm/src/Executors.kt Outdated Show resolved Hide resolved
@elizarov
Copy link
Contributor Author

I've made better tests and docs.

NOTE: It should be merged on the next major update (1.4.0) only, because it updates Delay interface APIs. Even though it is an @InternalCoroutinesApi, still extra caution will not harm.

When the Executor that was used with Executor.asCoroutineDispatcher() extension rejects submitted task, it means that it had reached its capacity and so the executing current Job should be cancelled to terminate it as soon as possible. This way RejectedExecutionException works as a rate-limiter just like it serves this purpose in executor-based Java code.

Fixes #2003
Reset dispatchers after each test in FailingCoroutinesMachineryTest. Otherwise some tests were running normally, but others with dispatchers that were already shutdown.
@elizarov elizarov merged commit 20341f2 into develop Oct 9, 2020
@elizarov elizarov deleted the executor-reject branch October 9, 2020 13:40
recheej pushed a commit to recheej/kotlinx.coroutines that referenced this pull request Dec 28, 2020
When the Executor that was used with Executor.asCoroutineDispatcher() extension rejects the submitted task, it means that it had reached its capacity and so the executing current Job should be canceled to terminate it as soon as possible. This way RejectedExecutionException works as a rate-limiter just like it serves this purpose in executor-based Java code.

Fixes Kotlin#2003
recheej pushed a commit to recheej/kotlinx.coroutines that referenced this pull request Dec 28, 2020
When the Executor that was used with Executor.asCoroutineDispatcher() extension rejects the submitted task, it means that it had reached its capacity and so the executing current Job should be canceled to terminate it as soon as possible. This way RejectedExecutionException works as a rate-limiter just like it serves this purpose in executor-based Java code.

Fixes Kotlin#2003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants