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

run Process#waitFor on virtual thread if available #3539

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

onsah
Copy link
Contributor

@onsah onsah commented Mar 6, 2025

Run Process.waitFor in virtual thread if possible to solve #3182

I am not sure if this is the correct approach but I wanted to share my progress to get fast feedback.

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Nice work, thanks for opening the PR, this is the right approach!

@onsah
Copy link
Contributor Author

onsah commented Mar 7, 2025

@armanbilge I think native test suites crash due to not being able to find getDeclaredMethod https://github.com/typelevel/fs2/actions/runs/13701427909/job/38315972895?pr=3539 How can we solve it?

@armanbilge
Copy link
Member

I think native test suites crash due to not being able to find getDeclaredMethod

That's correct, reflection is not supported on Scala Native.


How can we solve it?

We should move this code out of jvm-native sources into jvm, since it only works on the JVM.

@onsah
Copy link
Contributor Author

onsah commented Mar 7, 2025

@armanbilge If I understand correctly, this means we need two ProcessesCompanionPlatform then. Is it correct?

@armanbilge
Copy link
Member

this means we need two ProcessesCompanionPlatform then. Is it correct?

Well, that's one possible way ... but I think we should just move all this stuff into a different file, that's already split for the 3 platforms (JVM/JS/Native).

For example, we can add a method to ioplatform:

def evalOnVirtualThreadIfAvailable[F[_], A](fa: F[A]): F[A]

On the JVM, we can move it onto the VT executor if on JDK >= 21. On Native, we can do nothing.

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Nice work! One last change, we should make sure we test the Virtual Threads in CI using Java 21 (run sbt githubWorkflowGenerate to update the CI workflow):

fs2/build.sbt

Line 18 in 29d6876

ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17"))

@armanbilge armanbilge marked this pull request as ready for review March 7, 2025 23:07
@armanbilge armanbilge changed the title wip: run Process.waitFor on virtual thread if available run Process#waitFor on virtual thread if available Mar 7, 2025
@onsah
Copy link
Contributor Author

onsah commented Mar 8, 2025

@armanbilge I run Test/dependencyTree on the scalafix project and I see that scalatest version is 3.2.19. I searched for FunSuiteLike in docs but it doesn't exist https://www.scalatest.org/scaladoc/3.2.19/org/index.html?search=FunSuiteLike. There is a similar trait called AnyFunSuiteLike. Should we change to that or drop the dependency version of scalafix?

@armanbilge
Copy link
Member

@onsah good investigation! Yes, I think we should switch to AnyFunSuiteLike.

@onsah
Copy link
Contributor Author

onsah commented Mar 8, 2025

@armanbilge seems like there is a bug in one of the scalafix rules that causes a test to fail. Seems like irrelevant to the changes on this PR. Is it a general issue?

@armanbilge
Copy link
Member

armanbilge commented Mar 8, 2025

@onsah the problem is that now that we added JDK 21 to the CI, the scalafix had not been updated in a while and was not working.

I tried a bit too hard to fix it in your PR (updating versions, fixing the test suite, but now we still needother changes) ... I'm sorry, we should have just resolved in a separate PR 😅

In anycase, it's not a "bug" per se, just some changes we need to make as part of the version update. Feel free to open another PR if you want to give that a try, otherwise I will try to fix it soon.

@armanbilge
Copy link
Member

@onsah
Copy link
Contributor Author

onsah commented Mar 11, 2025

Thank you! I checked the scalafix PR. As soon as it's merged I can rebase this PR.

@armanbilge
Copy link
Member

there you go, it's merged :)

@onsah onsah requested a review from armanbilge March 11, 2025 11:16
Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Nice work, this looks good to me!

@onsah
Copy link
Contributor Author

onsah commented Mar 11, 2025

Thanks @armanbilge! Who can merge it? I don't see any button to do it myself.

@armanbilge
Copy link
Member

@onsah I'll give a little time in case anybody else wants to review, otherwise I will merge in the next day or two :)

Btw, I just realized, we can also use virtual threads for the JDK unix sockets implementation:

private[unixsocket] class JdkUnixSocketsImpl[F[_]: Files](implicit F: Async[F])

@onsah
Copy link
Contributor Author

onsah commented Mar 11, 2025

@armanbilge I will check this in the meantime, if it's already merged I can prepare a separate PR.

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.

2 participants