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

sample hangs if Scala 3 is used #3

Open
pjfanning opened this issue Oct 17, 2024 · 5 comments
Open

sample hangs if Scala 3 is used #3

pjfanning opened this issue Oct 17, 2024 · 5 comments

Comments

@pjfanning
Copy link
Owner

pjfanning commented Oct 17, 2024

Seen with Scala 3.3.4 and 3.5.1. HTTP requests to http://localhost:12345/api-docs/swagger.json hang.

Reported initially by @luksow - theiterators/kebs#282 (comment)

@pjfanning
Copy link
Owner Author

pjfanning commented Oct 17, 2024

I have a simpler version of the sample in https://github.com/pjfanning/swagger-pekko-http-sample/tree/scala3 (ie this repo but scala3 branch).

Use sbt run to run the HTTP server and to test use:
curl -v http://localhost:12345/hello

This hangs with Scala 3 but switch the build.sbt to Scala 2.13.15 and restart the HTTP server. The curl command then works fine.

Switching to Pekko 1.0 does not alter the result. The Scala 3 hang still happens.

@pjfanning
Copy link
Owner Author

pjfanning commented Oct 17, 2024

I kept stripping out parts of the code and the issue remained. The final thing that I removed and that then fixed the sample was removing the CORS code in the Rest object. If I remove that, the sample runs ok in Scala 3.

@jrudolph
Copy link

The problem is that you Await in Rest$, so you block the class initializer from completing but then there's some weird stuff going on that tries to access the fields (execution context, system) in Rest$ during request handling and that hangs. So, it's probably related to a different App compilation strategy in Scala 3.

@jrudolph
Copy link

jrudolph commented Oct 18, 2024

(The stack trace from jstack also reference lines in Rest.scala that don't exist, so there's definitely something funky...)

@jrudolph
Copy link

The problem is this:

val routes =
    cors()(new HelloService().route)

which desugars to something like

val routes =
    cors().apply(() => new HelloService(this.executionContext).route)

where you recreate the service on every call and therefore close over Rest$ for accessing the executionContext field leading to the deadlock.

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

No branches or pull requests

2 participants