-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix StackOverflowError with select expressions #1524
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qwwdfsad
requested changes
Sep 18, 2019
binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt
Outdated
Show resolved
Hide resolved
qwwdfsad
approved these changes
Sep 19, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please squash and merge
b7d142d
to
769e542
Compare
* onSend/onReceive clauses on the same channel: Instead of StackOverflowError we throw IllegalStateException and leave the channel in the original state. * Fix SOE in select with "opposite channels" stress-test. The fix is based on the sequential numbering of atomic select operation. Deadlock is detected and the operation with the lower sequential number is aborted and restarted (with a larger number). Fixes #504 Fixes #1411
769e542
to
6807cf0
Compare
elizarov
added a commit
that referenced
this pull request
Sep 22, 2019
This bug was introduced by #1524. The crux of problem is that TryOffer/PollDesc.onPrepare method is no longer allowed to update fields in these classes (like "resumeToken" and "pollResult") after call to tryResumeSend/Receive method, because the latter will complete the ongoing atomic operation and helper method might find it complete and try reading "resumeToken" which was not initialized yet. This change removes "pollResult" field which was not really needed ("result.pollResult" field is used) and removes "resumeToken" by exploiting the fact that current implementation of CancellableContinuationImpl does not need a token anymore. However, CancellableContinuation.tryResume/completeResume ABI is left intact, because it is used by 3rd party code. This fix lead to overall simplification of the code. A number of fields and an auxiliary IdempotentTokenValue class are removed, tokens used to indicate various results are consolidated, so that resume success is now consistently indicated by a single RESUME_TOKEN symbol. Fixes #1561
elizarov
added a commit
that referenced
this pull request
Sep 23, 2019
This bug was introduced by #1524. The crux of problem is that TryOffer/PollDesc.onPrepare method is no longer allowed to update fields in these classes (like "resumeToken" and "pollResult") after call to tryResumeSend/Receive method, because the latter will complete the ongoing atomic operation and helper method might find it complete and try reading "resumeToken" which was not initialized yet. This change removes "pollResult" field which was not really needed ("result.pollResult" field is used) and removes "resumeToken" by exploiting the fact that current implementation of CancellableContinuationImpl does not need a token anymore. However, CancellableContinuation.tryResume/completeResume ABI is left intact, because it is used by 3rd party code. This fix lead to overall simplification of the code. A number of fields and an auxiliary IdempotentTokenValue class are removed, tokens used to indicate various results are consolidated, so that resume success is now consistently indicated by a single RESUME_TOKEN symbol. Fixes #1561
elizarov
added a commit
that referenced
this pull request
Sep 23, 2019
This bug was introduced by #1524. The crux of problem is that TryOffer/PollDesc.onPrepare method is no longer allowed to update fields in these classes (like "resumeToken" and "pollResult") after call to tryResumeSend/Receive method, because the latter will complete the ongoing atomic operation and helper method might find it complete and try reading "resumeToken" which was not initialized yet. This change removes "pollResult" field which was not really needed ("result.pollResult" field is used) and removes "resumeToken" by exploiting the fact that current implementation of CancellableContinuationImpl does not need a token anymore. However, CancellableContinuation.tryResume/completeResume ABI is left intact, because it is used by 3rd party code. This fix lead to overall simplification of the code. A number of fields and an auxiliary IdempotentTokenValue class are removed, tokens used to indicate various results are consolidated, so that resume success is now consistently indicated by a single RESUME_TOKEN symbol. Fixes #1561
elizarov
added a commit
that referenced
this pull request
Sep 26, 2019
This bug was introduced by #1524. The crux of problem is that TryOffer/PollDesc.onPrepare method is no longer allowed to update fields in these classes (like "resumeToken" and "pollResult") after call to tryResumeSend/Receive method, because the latter will complete the ongoing atomic operation and helper method might find it complete and try reading "resumeToken" which was not initialized yet. This change removes "pollResult" field which was not really needed ("result.pollResult" field is used) and removes "resumeToken" by exploiting the fact that current implementation of CancellableContinuationImpl does not need a token anymore. However, CancellableContinuation.tryResume/completeResume ABI is left intact, because it is used by 3rd party code. This fix lead to overall simplification of the code. A number of fields and an auxiliary IdempotentTokenValue class are removed, tokens used to indicate various results are consolidated, so that resume success is now consistently indicated by a single RESUME_TOKEN symbol. Fixes #1561
elizarov
added a commit
that referenced
this pull request
Sep 26, 2019
This bug was introduced by #1524. The crux of problem is that TryOffer/PollDesc.onPrepare method is no longer allowed to update fields in these classes (like "resumeToken" and "pollResult") after call to tryResumeSend/Receive method, because the latter will complete the ongoing atomic operation and helper method might find it complete and try reading "resumeToken" which was not initialized yet. This change removes "pollResult" field which was not really needed ("result.pollResult" field is used) and removes "resumeToken" by exploiting the fact that current implementation of CancellableContinuationImpl does not need a token anymore. However, CancellableContinuation.tryResume/completeResume ABI is left intact, because it is used by 3rd party code. This fix lead to overall simplification of the code. A number of fields and an auxiliary IdempotentTokenValue class are removed, tokens used to indicate various results are consolidated, so that resume success is now consistently indicated by a single RESUME_TOKEN symbol. Fixes #1561
elizarov
added a commit
that referenced
this pull request
Oct 2, 2019
This bug was introduced by PR #1524. It was reproducing when there is a regular "send" operation on one side of a channel and "select { onReceive }" on another side of the channel and the "send" coroutine gets cancelled. The problem is that SendElement.tryResumeSend implementation was calling finishPrepare before it has successfully resumed continuation, so if that continuation was already cancelled, the code in "finishPrepare" had already stored the wrong affected node which it would later try to call "completeResume" on. This patch also adds hexAddress to the debug toString method of all internal node classes in channel implementation. Fixes #1588
elizarov
added a commit
that referenced
this pull request
Oct 2, 2019
This bug was introduced by PR #1524. It was reproducing when there is a regular "send" operation on one side of a channel and "select { onReceive }" on another side of the channel and the "send" coroutine gets cancelled. The problem is that SendElement.tryResumeSend implementation was calling finishPrepare before it has successfully resumed continuation, so if that continuation was already cancelled, the code in "finishPrepare" had already stored the wrong affected node which it would later try to call "completeResume" on. This patch also adds hexAddress to the debug toString method of all internal node classes in channel implementation. Fixes #1588
elizarov
added a commit
that referenced
this pull request
Oct 3, 2019
This bug was introduced by PR #1524. It was reproducing when there is a regular "send" operation on one side of a channel and "select { onReceive }" on another side of the channel and the "send" coroutine gets cancelled. The problem is that SendElement.tryResumeSend implementation was calling finishPrepare before it has successfully resumed continuation, so if that continuation was already cancelled, the code in "finishPrepare" had already stored the wrong affected node which it would later try to call "completeResume" on. This patch also adds hexAddress to the debug toString method of all internal node classes in channel implementation. Fixes #1588
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
StackOverflowError we throw IllegalStateException and leave
the channel in the original state.
based on the sequential numbering of atomic select operation.
Deadlock is detected and the operation with the lower sequential
number is aborted and restarted (with a larger number).
Fixes #504
Fixes #1411