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

Structured concurrency & Job cancellation improvements #1020

Merged
merged 7 commits into from
Mar 13, 2019

Conversation

elizarov
Copy link
Contributor

@elizarov elizarov commented Mar 1, 2019

Structured concurrency for Completable/Listenable futures

BREAKING BEHAVIOR CHANGE:

  • kotlinx-coroutines-jdk8 and -guava integration modules
      future { ... } builders now honor structured concurrency in
      the same way as all other builders -- a failure inside the child
      (builder) code now cancels parent coroutine.
      Note that is does not affect non-structured (typical) usage like
      GlobalScope.future { ... }

MINOR BEHAVIOR CHANGE:

  • Exception in installed CancellableCoroutine.invokeOnCancellation
      handler does not cancel the parent job, but is considered to be an
      uncaught exception, so it goes to CoroutineExceptionHandler.

Internal changes:

  • JobSupport.cancelsParents=true is now a default, since there are
      only a fewer exceptions for builder that throw their exception from block
  • JobSupport.handleJobException has additional "handled" parameter to
      distinguish cases when parent did/did-not handle it.
  • handleCoroutineException logic is updated. It never cancels parent,
      since parent cancellation is taken care of by structured concurrency.
  • handleCoroutineException is always invoked with current coroutine's
      context (as opposed to parent)

Fixes #1007

Hide cancel(Throwable), introduce cancel(CancellationException)

Job/ReceiveChannel/BroadcastChannel.cancel(Throwable) is now hidden and
cannot be invoked from a newly compiled code. This function had broken
semantics when used with an arbitrary exception. A safe replacement
is available in the form of cancel(CancellationException) where
CancellationException can be used to supply additional information
for debugging purposes.

Fixes #975

BREAKING BEHAVIOR CHANGE:

* kotlinx-coroutines-jdk8 and -guava integration modules
  future { ... } builders now honor structured concurrency in
  the same way as all other builders -- a failure inside the child
  (builder) code now cancels parent coroutine.
  Note that is does not affect non-structured (typical) usage like
  GlobalScope.future { ... }

MINOR BEHAVIOR CHANGE:

* Exception in installed CancellableCoroutine.invokeOnCancellation
  handler does not cancel the parent job, but is considered to be an
  uncaught exception, so it goes to CoroutineExceptionHandler.

Internal changes:

* JobSupport.cancelsParents=true is now a default, since there are
  only a fewer exceptions for builder that throw their exception from block
* JobSupport.handleJobException has additional "handled" parameter to
  distinguish cases when parent did/did-not handle it.
* handleCoroutineException logic is updated. It never cancels parent,
  since parent cancellation is taken care of by structured concurrency.
* handleCoroutineException is always invoked with current coroutine's
  context (as opposed to parent)

Fixes #1007
Job/ReceiveChannel/BroadcastChannel.cancel(Throwable) is now hidden and
cannot be invoked from a newly compiled code. This function had broken
semantics when used with an arbitrary exception. A safe replacement
is available in the form of cancel(CancellationException) where
CancellationException can be used to supply additional information
for debugging purposes.

Fixes #975
@elizarov elizarov requested a review from qwwdfsad March 1, 2019 12:09
This simplifies trouble-shooting of "what caused cancellation", as you
can print out exception and see its recovered stack trace.
@qwwdfsad qwwdfsad merged commit d202ed9 into develop Mar 13, 2019
@qwwdfsad qwwdfsad deleted the cancel-exception branch March 13, 2019 11:22
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