Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[backport] ImprovedInterruptedException handling forFutures#10379

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
SethTisue merged 2 commits intoscala:2.12.xfromszeiger:wip/future-interrupt
Jan 18, 2024

Conversation

@szeiger
Copy link
Contributor

@szeigerszeiger commentedApr 24, 2023
edited by SethTisue
Loading

Previously, anInterruptedException might cause aFuture to never complete. Now the future will fail.

Thisfixesscala/bug#8938 for Scala 2.12 in a way that is compatible with the behavior of 2.13 introduced in05c2b43.

  • Relevant test suite parts taken verbatim from the 2.13 version, with one exception: I did not modify the messages of wrapped exceptions, therefore PromiseTests expects the name "Boxed InterruptedException" (as used inPromise.resolver in 2.12) instead of "Boxed Exception".
  • The actual implementation is not based on 2.13, which was a major rewrite that cannot be applied cleanly to 2.12 and is not fully source or binary compatible. Instead I implemented a strategic fix in as simple a way as possible.

He-Pin and lrytz reacted with heart emoji
Thisfixesscala/bug#8938 for Scala 2.12 in a way that is compatible with the behavior of 2.13 introduced in05c2b43.- Relevant test suite parts taken verbatim from the 2.13 version, with one exception: I did not modify the messages of wrapped exceptions, therefore PromiseTests expects the name "Boxed InterruptedException" (as used in `Promise.resolver` in 2.12) instead of "Boxed Exception".- The actual implementation is not based on 2.13, which was a major rewrite that cannot be applied cleanly to 2.12 and is not fully source or binary compatible. Instead I implemented a strategic fix in as simple a way as possible.
@scala-jenkinsscala-jenkins added this to the2.12.18 milestoneApr 24, 2023
@SethTisueSethTisue added the library:concurrentChanges to the concurrency support in stdlib labelApr 24, 2023
@SethTisueSethTisue changed the titleInterruptedException handling for Futures[backport] InterruptedException handling for FuturesApr 24, 2023

private[this]finaldefwrapFailure(t:Throwable):Throwable= {
if (NonFatal(t)) t
elseif (t.isInstanceOf[InterruptedException])newExecutionException("Boxed InterruptedException", t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It seems 2.13 alsocallsThread.currentThread.interrupt(), should that be done here too?

#6610 says "Makes Futures correctly handle Thread.interrupt", I don't know what that entails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The newextended example shows receiving the ExecutionException; on 2.12 it currently throws up the stack; with this fix, the world is right again. I just waffled on whether to re-interrupt inthis fix for vulpix whereprocess.waitFor is interrupted bypool.shutdown. It should interrupt (after retrying its work) in case subsequent work happens on the worker thread, even though one might assume that one is the last "client" of the thread. So I'd vote for interrupting the current (worker) thread.

I've forgotten the brouhaha over running side effects on the "current" thread; is there such an executor? But maybe it is irrelevant whether we know who created the current thread. If we caught the exception, we should set the interrupt status.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't really understand that part and it's not obvious how to adapt it to the 2.12 design which is completely different. Since the new test suite passes with this version, it's obviously untested (and unspecified). Is the idea to always interrupt the current thread if a Promise was completed with a boxed InterruptedException?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is the idea to always interrupt the current thread if a Promise was completed with a boxed InterruptedException?

That's how the 2.13 code reads.

Googlin' I find many places that say "if you catch anInterruptedException, you should callThread.currentThread.interrupt()"

summon[@viktorklang]?

som-snytt reacted with laugh emoji
Copy link
ContributorAuthor

@szeigerszeigerJun 2, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Updated to add the same interrupt handling as in 2.13 (i.e. not always interrupting whenInterruptedException was caught but only when the promise was successfully completed with this exception).

@SethTisueSethTisue added the release-notesworth highlighting in next release notes labelMay 1, 2023
@SethTisueSethTisue modified the milestones:2.12.18,2.12.19May 1, 2023
Copy link
Member

@lrytzlrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM. More reviews welcome...

@SethTisueSethTisue merged commitc3cd9a7 intoscala:2.12.xJan 18, 2024
@SethTisue
Copy link
Member

SethTisue commentedJan 18, 2024
edited
Loading

It does make me nervous to tinker with this at this late stage in 2.12 development. But we shouldn't be unreasonably scared, given that the bug this addresses is rather serious.

Thank you, Stefan. And, fingers crossed!

som-snytt and lrytz reacted with heart emoji

@som-snytt
Copy link
Contributor

Worst case, any commit on 2.12 helps get people off 2.12.

@SethTisueSethTisue changed the title[backport] InterruptedException handling for Futures[backport] ImprovedInterruptedException handling forFuturesFeb 6, 2024
hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this pull requestMay 2, 2025
[backport] InterruptedException handling for Futures
hamzaremmal pushed a commit to scala/scala3 that referenced this pull requestMay 7, 2025
[backport] InterruptedException handling for Futures
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@som-snyttsom-snyttsom-snytt left review comments

@lrytzlrytzlrytz approved these changes

Assignees

No one assigned

Labels

library:concurrentChanges to the concurrency support in stdlibrelease-notesworth highlighting in next release notes

Projects

None yet

Milestone

2.12.19

Development

Successfully merging this pull request may close these issues.

5 participants

@szeiger@SethTisue@som-snytt@lrytz@scala-jenkins

[8]ページ先頭

©2009-2025 Movatter.jp