sjrd/scalajs-sbt-vite-laminar-chartjs-example

`java.lang.StackOverflowError` crash when running `npm run dev`

guizmaii opened this issue · 2 comments

If I manually run in a shell sbt --error "print myFrontEndModule/fastLinkOutputDir", sbt exists with 0 but if I run sbt --error --batch "print myFrontEndModule/fastLinkOutputDir", then sbt crashes with:

java.lang.StackOverflowError
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5074)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
       ...

sbt version: 1.9.6
Scala version: 2.13.12
ScalaJS version: 1.14.0
OS: macOS
Node version: v20.8.0

Edit:
Insterestingly, adding -mem 4096 fixes this issue when I launch the sbt command manually in a shell:

sbt -mem 4096 --error --batch "print myFrontEndModule/fastLinkOutputDir"

but when I run npm run dev, then I always have a similar stackoverflow error:

java.lang.StackOverflowError
        at java.base/java.util.regex.Pattern$Slice.match(Pattern.java:4265)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
        at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:5078)
        at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:5000)
        at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4878)
        at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:4110)
        at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4914)
        at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4969)
...
failed to load config from /Users/jules/.../vite.config.js
error when starting dev server:
Error: sbt process failed with exit code 1
    at printSbtTask (file:///...vite.config.js.timestamp-1696411233087-090230946b924.mjs:23:11)
    at file:///.../vite.config.js.timestamp-1696411233087-090230946b924.mjs:26:31
sjrd commented

It's quite surprising that giving more RAM solves a Stack Overflow deep within Java's regex engine, of all things.

Does the problem go away (including with npm run dev) if you put the following inside a file called .sbtopts (next to build.sbt):

-mem
4096

?

@sjrd Adding the .sbtopts file does solve the stackoverflow 🎉
Thanks a lot Sébastien!

I think I know why I have this stackoverflow, at least I think I know the culprit.
I'm using sbt-dotenv and if I disable it (but I need it) the stackoverflow also disapears