scala-js / scala-js-js-envs

Spawn and communicate with JavaScript environments on the JVM
Apache License 2.0
0 stars 4 forks source link

'Scala.js Com failed: ECONNREFUSED' for Com runs with Node.js 17 #12

Closed sjrd closed 2 years ago

sjrd commented 2 years ago

It seems that our Com setup for the Node.js env is completely broken on Node.js 17. The symptom in a Scala.js application is

[info] Fast optimizing /localhome/doeraene/projects/scalajs/test-suite/js/.2.12/target/scala-2.12/scalajs-test-suite-test-fastopt
Scala.js Com failed: Error: connect ECONNREFUSED ::1:40091
[error] stack trace is suppressed; run last testSuite2_12 / Test / loadedTestFrameworks for the full output
[error] (testSuite2_12 / Test / loadedTestFrameworks) org.scalajs.testing.common.RPCCore$ClosedException: org.scalajs.testing.adapter.JSEnvRPC$RunTerminatedException
[error] Total time: 49 s, completed Nov 2, 2021 4:31:29 PM

The test suite of this repo indeed fails on Node.js 17.0.1, whereas it passes on 16.13.0:

sbt:root> scalajs-env-nodejs/test
[info] compiling 1 Scala source to /localhome/doeraene/projects/scalajs-js-envs/js-envs/target/scala-2.12/classes ...
[error] Test org.scalajs.jsenv.test.RunTests.catchExceptionTest[config = Node.js, withCom = true] failed: closing a ComRun failed unexpectedly, took 0.041 sec
[error] Test org.scalajs.jsenv.test.RunTests.multiCloseAfterTerminatedTest[config = Node.js, withCom = true] failed: closing a ComRun failed unexpectedly, took 0.036 sec
[error] Test org.scalajs.jsenv.test.RunTests.defaultFilesystem[config = Node.js, withCom = true] failed: closing a ComRun failed unexpectedly, took 0.039 sec
[error] Test org.scalajs.jsenv.test.RunTests.allowScriptTags[config = Node.js, withCom = true] failed: closing a ComRun failed unexpectedly, took 0.038 sec
[error] Test org.scalajs.jsenv.test.RunTests.percentageTest[config = Node.js, withCom = true] failed: closing a ComRun failed unexpectedly, took 0.04 sec
[error] Test org.scalajs.jsenv.test.RunTests.fastCloseTest[config = Node.js, withCom = true] failed: closing a ComRun failed unexpectedly, took 0.038 sec
[error] Test org.scalajs.jsenv.test.RunTests.utf8Test[config = Node.js, withCom = true] failed: closing a ComRun failed unexpectedly, took 0.037 sec
[error] Test org.scalajs.jsenv.test.TimeoutRunTests.basicTimeoutTest[config = Node.js, withCom = true] failed: reached end of stream, took 0.044 sec
[error] Test org.scalajs.jsenv.test.TimeoutRunTests.intervalTest[config = Node.js, withCom = true] failed: reached end of stream, took 0.038 sec
[error] Test org.scalajs.jsenv.test.ComTests.separateComStdoutTest[config = Node.js] failed: no messages left and run has completed, took 0.039 sec
[error] Test org.scalajs.jsenv.test.ComTests.basicTest[config = Node.js] failed: no messages left and run has completed, took 0.038 sec
[error] Test org.scalajs.jsenv.test.ComTests.jsExitsOnMessageTest[config = Node.js] failed: no messages left and run has completed, took 0.039 sec
[error] Test org.scalajs.jsenv.test.ComTests.largeMessageTest[config = Node.js] failed: no messages left and run has completed, took 0.052 sec
[error] Test org.scalajs.jsenv.test.ComTests.highCharTest[config = Node.js] failed: no messages left and run has completed, took 0.037 sec
[error] Test org.scalajs.jsenv.test.ComTests.multiEnvTest[config = Node.js] failed: no messages left and run has completed, took 0.046 sec
[error] Test org.scalajs.jsenv.test.ComTests.noInitTest[config = Node.js] failed: closing a ComRun failed unexpectedly, took 0.041 sec
[error] Test org.scalajs.jsenv.test.TimeoutComTests.noImmediateCallbackTest[config = Node.js] failed: closing a ComRun failed unexpectedly, took 0.037 sec
[error] Test org.scalajs.jsenv.test.TimeoutComTests.noMessageTest[config = Node.js] failed: closing a ComRun failed unexpectedly, took 0.037 sec
[error] Test org.scalajs.jsenv.test.TimeoutComTests.intervalSendTest[config = Node.js] failed: no messages left and run has completed, took 0.038 sec
[error] Test org.scalajs.jsenv.test.TimeoutComTests.delayedReplyTest[config = Node.js] failed: no messages left and run has completed, took 0.039 sec
[error] Test org.scalajs.jsenv.test.TimeoutComTests.delayedInitTest[config = Node.js] failed: no messages left and run has completed, took 0.039 sec
[error] Failed: Total 42, Failed 21, Errors 0, Passed 21
[error] Failed tests:
[error]         org.scalajs.jsenv.nodejs.NodeJSSuite
[error] (scalajs-env-nodejs / Test / test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 7 s, completed Nov 2, 2021 4:37:55 PM

This issue makes any test task in a Scala.js project completely unusable.

sjrd commented 2 years ago

Found it. It is an instance of the upstream issue https://github.com/nodejs/node/issues/40537, which is a consequence of an intended change of behavior https://github.com/nodejs/node/pull/39987. The JVM server for the Com runs on IPv4, but Node.js now tries to connect to it via IPv6.

Workaround

As a workaround, pass the --dns-result-order=ipv4first option to the Node.js environment, using

new NodeJSEnv(NodeJSEnv.Config().withArgs(List("--dns-result-order=ipv4first")))

For example, in an sbt build, that would be in a setting like

import org.scalajs.jsenv.nodejs.NodeJSEnv

jsEnv := new NodeJSEnv(NodeJSEnv.Config().withArgs(List("--dns-result-order=ipv4first")))
sjrd commented 2 years ago

New workaround until Scala.js v1.8.0

We have now published scalajs-env-nodejs v1.2.1, which contains a proper fix to this issue. It will be included in Scala.js 1.8.0, but that is not for tomorrow. In the meantime, you may force scalajs-env-nodejs v1.2.1 to be used, even with older Scala.js versions, with the following setting in project/plugins.sbt :

libraryDependencies += "org.scala-js" %% "scalajs-env-nodejs" % "1.2.1"