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

play hangs on console interacton when using jblas library #12355

Open
civic9 opened this issue Feb 11, 2024 · 6 comments
Open

play hangs on console interacton when using jblas library #12355

civic9 opened this issue Feb 11, 2024 · 6 comments

Comments

@civic9
Copy link

civic9 commented Feb 11, 2024

Play Version

3.0.1 (but probably all versions since 2.8.12)

API

Java

Operating System

Windows Server 2016 Std, Windows 10
Linux version is not affected by this issue.

JDK

openjdk version "21.0.1" 2023-10-17 LTS
OpenJDK Runtime Environment Temurin-21.0.1+12 (build 21.0.1+12-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.1+12 (build 21.0.1+12-LTS, mixed mode, sharing)

but tested with same results also on other distributions (oracle) and versions (11, 17).

Library Dependencies

"org.jblas" % "jblas" % "1.2.5", // https://github.com/jblas-project/jblas

Expected Behavior

  1. create play-java-seed project.

  2. include
    "org.jblas" % "jblas" % "1.2.5"
    in libraryDependencies in build.sbt

  3. create simple controller like this:

package controllers;

import play.mvc.*;
import org.jblas.DoubleMatrix;
import org.jblas.MatrixFunctions;

public class JblasTest extends Controller {

	public Result index() {

		System.out.println("STEP 1");
		DoubleMatrix Ms = new DoubleMatrix(5,5);

		System.out.println("STEP 2");
		Ms = Ms.mul(2);

		System.out.println("STEP 3");
		DoubleMatrix expMs = MatrixFunctions.expm(Ms); // JNI call in jblas

		System.out.println("STEP 4");
		return ok("OK");
	}

}

This code should just execute without any problems and print STEP 1-4 to the standard output.

Actual Behavior

Play (or more precisely just current thread handling a request) hangs when
MatrixFunctions.expm is invoked therefore it only prints STEP 1, 2 and 3 on the stardard output.
Calling standard jblas functions as in STEP 1 and STEP 2 works fine,
but play hangs on STEP 3 which afaik uses JNI in jblas.

But if I enter two characters using keyboard on play console, the execution completes and STEP 4 is printed.

Reproducible Test Case

This can be tested even with such one line of code:

System.out.println("STEP1");
MatrixFunctions.expm(new DoubleMatrix(5,5));
System.out.println("STEP2");

Other comments

I just upgraded my project from old 2.8.x play framework to the latest 3.0.1.
On the first 2.8.x releases this worked without any problems.
I have checked this code in many older versions.
This code works without any problems up to and including version 2.8.11.
As of version 2.8.12 (and probably all newer ones) it hangs as described above.
As I can see in the commit history there have been some changes in consolereader between those versions,
maybe it is related to this issue.

This code also works fine outside of play, I don't see any
interactions with standard input or console.

@mkurz
Copy link
Member

mkurz commented Feb 22, 2024

So this is most likely caused by

Which version of sbt are you using in your project/build.properties? Please try with sbt version 1.7.2 when using Play 2.8.12+ or sbt 1.9.7 when using Play 2.9 or 3.0 and let me know if that fixes the problem.

However, given that this is working on Linux and "only" broken on Windows and the fact that this very likely is a problem only in dev mode, but should work fine in prod mode, I will not spend time to fix this problem. Also probably sbt magic is involved here as well...

If you want to fix this, I am happy to review a pull request. But I am not going to look further into this issue at this point.

@civic9
Copy link
Author

civic9 commented Feb 23, 2024

Yes, it works fine in prod mode, only dev mode is affected.

The issue still occurs with sbt 1.7.2 (Play 2.8.12) and sbt 1.9.7 (Play 2.9).

We can run Play using:

 echo | set /p dummyName=abc | sbt run

This passes the string "abc" (no new line, this is important) to Play input,
which satisfies the need for Play/sbt to consume some input, and jblas is working fine.

But after this Java process causes high CPU usage permanently :(

I can't fix it this myself, sbt and scala are black magic to me.

@mkurz
Copy link
Member

mkurz commented Feb 24, 2024

For the sake of completeness, can you also try sbt 1.9.9? (I don't expect it to work actually, but they did upgrade Jline in the release, so who knows)
Like said I will not prioritize this issue currently since it's "only" broken when using Windows, in dev mode, when pulling in the jblas library. Maybe someone steps up to invest time, also in case that's you I am happy to review a pull request.
Thanks for reporting anyway!

@civic9
Copy link
Author

civic9 commented Feb 24, 2024

The issue still occurs with sbt 1.9.9 (Play 2.9).

I understand this is a low priority issue.

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

3 participants
@mkurz @civic9 and others