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

Make object wrapper extend DelayedInit #2535

Conversation

MaciejG604
Copy link
Contributor

@MaciejG604 MaciejG604 commented Nov 13, 2023

Fixes #2470

Thanks to @rochala for suggesting the solution of using a wrapper that extends App.

This simple fix seems to have been overlooked in the past, probably because it has some quirks when it comes to different Scala versions.

For Scala 2.12 and 2.13 an object that extends App avoids the deadlock when background threads are started from its initialization clause.
However, this is not true for Scala 3, it is a known bug that has not been fixed yet - scala/scala3#16149

Object wrapper extending DelayedInit can be chosen with --delayed-init and //> using delayedInit.wrapper.
This wrapper will not suffer from deadlocks in Scala 2.13 and 2.12 when background threads are used.

Since DelayedInit is deprecated, this mechanism won't be the default.
Using App instead of DelayedInit requires a bit more work as it introduces an extra main function, which messes up with Scala CLI's main class inference from scripts.

@MaciejG604 MaciejG604 force-pushed the make-object-wrapper-extend-delayed-init branch from b2d2c91 to 0439500 Compare November 14, 2023 09:46
@MaciejG604 MaciejG604 force-pushed the make-object-wrapper-extend-delayed-init branch from 0439500 to a0a6158 Compare November 15, 2023 08:42
@MaciejG604 MaciejG604 marked this pull request as ready for review November 15, 2023 10:34
Copy link
Contributor

@Gedochao Gedochao left a comment

Choose a reason for hiding this comment

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

LGTM

@som-snytt
Copy link

This simple fix seems to have been overlooked in the past

Previous REPL wrap is App scala/scala#4246

Uncharacteristically, I submitted it three times. I don't remember why it did not fly.

@MaciejG604 MaciejG604 marked this pull request as draft November 16, 2023 15:01
@MaciejG604
Copy link
Contributor Author

May be replaced by #2556

@MaciejG604
Copy link
Contributor Author

Replaced by #2556

@MaciejG604 MaciejG604 closed this Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scala-cli stalls when awaiting every single result from a list of Futures.
3 participants