Skip to content

SI-8689 Avoid internal error in Promise after sequence of completions #4289

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

Merged
merged 1 commit into from
Feb 15, 2015

Conversation

retronym
Copy link
Member

@retronym retronym commented Feb 3, 2015

Calling completeWith when the DefaultPromise is already completed,
leads to callbacks not being properly executed.

This happened because Future.InternalCallbackExecutor extends
BatchingExecutor[1] which assumes unbatchedExecute to be async,
when in this case it is sync, and if there is an exception thrown
by executing the batch, it creates a new batch with the remaining
items from the current batch and submits that to unbatchedExecute
and then rethrows, but if you have a sync unbatchedExecute, it will
fail since it is not reentrant, as witnessed by the failed require
as reported in this issue.

This commit avoids problem by delegating completeWith to
tryComplete, which has the effect of using onComplete +
tryComplete i.s.o. complete, which means that when it fails
(because of a benign race condition between completers) it won't
throw an exception.

It has been tested by the minimized reproducer.

[1] Actually, in the 2.10.x branch where this patch is starting out,
"The BatchingExecutor trait had to be inlined into
InternalCallbackExecutor for binary compatibility.". This comment
will be more literally correct in the context of 2.11.x and beyond

@scala-jenkins scala-jenkins added this to the 2.10.5 milestone Feb 3, 2015
@retronym
Copy link
Member Author

retronym commented Feb 3, 2015

Retargets #4215 to the 2.10.x branch, from whence it will flow to 2.11.x and 2.12.x.

Review by @viktorklang (the author of the patch) and @axel22.

I confirmed that the added test cases failed without the change to completeWith.

@adriaanm
Copy link
Contributor

adriaanm commented Feb 3, 2015

Egad! Time to backport the CI scripts from #4268 to 2.10... Looking at it.

@adriaanm
Copy link
Contributor

adriaanm commented Feb 3, 2015

If I winged it successfully with #4290, please rebase on top.

@viktorklang
Copy link
Contributor

👍

@axel22
Copy link
Contributor

axel22 commented Feb 3, 2015

LGTM

On 3 February 2015 06:51:47 GMT, Jason Zaugg [email protected] wrote:

Retargets #4215 to the 2.10.x branch, from whence it will flow to
2.11.x and 2.12.x.

Review by @viktorklang (the author of the patch) and @axel22.

I confirmed that the added test cases failed without the change to
completeWith.


Reply to this email directly or view it on GitHub:
#4289 (comment)

Sent from my Android device with K-9 Mail. Please excuse my brevity.

Calling `completeWith` when the `DefaultPromise` is already completed,
leads to callbacks not being properly executed.

This happened because `Future.InternalCallbackExecutor` extends
`BatchingExecutor`[1] which assumes `unbatchedExecute` to be async,
when in this case it is sync, and if there is an exception thrown
by executing the batch, it creates a new batch with the remaining
items from the current batch and submits that to `unbatchedExecute`
and then rethrows, but if you have a sync `unbatchedExecute`, it will
fail since it is not reentrant, as witnessed by the failed `require`
as reported in this issue.

This commit avoids problem by delegating `completeWith` to
`tryComplete`, which has the effect of using `onComplete` +
`tryComplete` i.s.o. `complete`, which means that when it fails
(because of a benign race condition between completers) it won't
throw an exception.

It has been tested by the minimized reproducer.

[1] Actually, in the 2.10.x branch where this patch is starting out,
    "The BatchingExecutor trait had to be inlined into
    InternalCallbackExecutor for binary compatibility.". This comment
    will be more literally correct in the context of 2.11.x and beyond
@retronym
Copy link
Member Author

retronym commented Feb 4, 2015

Rebased on 2.10.x to get PR validation working, no code changes.

@adriaanm
Copy link
Contributor

adriaanm commented Feb 5, 2015

The failure can be ignored. Sorry.

@adriaanm
Copy link
Contributor

adriaanm commented Feb 6, 2015

/nothingtoseehere

gkossakowski added a commit that referenced this pull request Feb 15, 2015
SI-8689 Avoid internal error in Promise after sequence of completions
@gkossakowski gkossakowski merged commit ad845ff into scala:2.10.x Feb 15, 2015
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.

6 participants