IntelliJ can't connect to its own Scala compile server
Asked Answered
P

5

20

I am using latest IntelliJ IDEA (2016.1.1) - but I have seen this behaviour in previous versions too - developing in Scala with latest Scala plugin (3.0.3).

When I try to Run/Debug a test or code, IDEA will start Making the project, but will then stay there several seconds while the "Make" progress bar doesn't progress at all.

After 20-30 seconds of this, the following message appear in the Messages tab:

Warning:scala: Cannot connect to compile server at localhost/127.0.0.1:59656 Trying to compile without it

The port shown there, 59656, is a port I hard-coded myself in %USER_PROFILE%\.IntelliJIdea2016.1\config\options\scala.xml, after I noticed this problem the first time on the default port, so changing the port did not help...

At this point, the bar will read "Reading compilation settings..." for several more tens of seconds before the code actually runs. It is terribly bothering and I can't seem to be able to fix it definitively. This can easily take up to 3 minutes to run a single test. Very disrupting. I noticed this problem happening intermittently on my work machine (Win7).

Anyone has any idea how to debug/fix this issue?

Thanks

Pyrargyrite answered 29/4, 2016 at 8:59 Comment(6)
Also happens in Linux.Tremor
I've also experienced this issue on Windows 7. After I've upgraded to Windows 8.1 (and now 10), it went away (so far).Yusuk
Also happens on OSX.Dulce
I have the same on Win10 while trying a Scala WorksheetRonironica
The compile server keeps moving around to different ports, it's like a game of whack-a-mole. IntelliJ should be using named pipes for this, TCP for local machine compilation is just asinine.Impassable
Happened with me, too and I was pretty frustrated. Interestingly, restarting the IDE made this work. :DItchy
C
12

I had the same issue. I'm using IntelliJ 2017.3. Play framework 2.6. Stb 0.13.15. Solved with adding -server -Xss1m in the scala compile server JVM parameters: enter image description here

Cocklebur answered 15/1, 2018 at 5:10 Comment(0)
D
5

I don't fully understand this yet, however under Preferences, Languages & Frameworks > Scalac Server there are some settings that might help:

  • Shutdown server if it is idle for <number> minutes.
  • Use project home as compiler server working directory (Compile server will be restarted on each compilation of a new project)
  • JVM SDK is used to instantiate compile server ... (when JVM SDK and module SDK match).

There is a small icon in the bottom right of the IntelliJ window that indicates whether the compile server is running and can be used to stop and start it.

The server will shutdown if it is idle. It should normally start up when needed but this might not happen if the JVM SDK does not match the module SDK. Increasing the idle timeout should help to reduce the frequency of the problem. Matching the JVM SDK to the Module SDK ought to fix the problem, but might not be possible if you have multiple projects using different SDKs.

Using the project home as the compiler server working directory might help if you frequently switch between projects.

Edit

I have this problem again with IntelliJ IDEA Ultimate 2016.3.2 but the usual method of a clean shutdown and reboot hasn't worked. I've pieced together some information on how the compile server works and it seems to me that IntelliJ is looking on the wrong port for the compile server. If I manually force a make then I can see a compile server running, but it isn't the one that IntelliJ is looking for. I still don't have a solution, but this information might get us closer to one.

Finding Files

The first step is working out where IntelliJ stores its configuration and log files. This information is currently published here: IntelliJ Directories

On my Mac this means:

  • configuration files: ~/Library/Preferences/IntelliJIdea2016.3/options
  • log files: ~/Library/Logs/IntelliJIdea2016.3

The Compile Server

The compile server is a Java process with a very long command line that ends like this:

org.jetbrains.jps.cmdline.BuildMain <host> <port> <compile-server-id> <compile-server-cache-directory>

The configuration options are stored in ~/Library/Preferences/IntelliJIdea2016.3/options/scala.xml

Some of these are configured in the Preferences -> Languages & Frameworks -> Scala Compiler Server dialog, but other settings can be added by editing the file. Mine currently looks like this:

<application>
  <component name="ScalaSettings">
    <option name="COMPILE_SERVER_PORT" value="59184" />
    <option name="COMPILE_SERVER_ID" value="93f4589e-4707-4e20-a05a-01869045e067" />
    <option name="COMPILE_SERVER_SDK" value="1.8" />
    <option name="COMPILE_SERVER_MAXIMUM_HEAP_SIZE" value="2048" />
  </component>
</application>

I added the COMPILER_SERVER_PORT option by hand, but with this version of IntelliJ the compile server that it uses for single compilations has a different port and id. Unfortunately this process uses a different port if I change COMPILER_SERVER_PORT and restart IntelliJ so I think these are two separate instances.

I used this command to find the compile server process, after manually starting a compile:

ps -ef | grep nailgun

This command finds the ports used by IntelliJ:

lsof -i | grep idea

There is also a log file here:

~/Library/Logs/IntelliJIdea2016.3/idea.log

that indicates that something is not quite right:

2016-12-28 10:19:46,745 [  50710]   INFO - j.compiler.server.BuildManager - BUILDER_PROCESS [stdout]: Build process started. Classpath: /Users/richard/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/163.10154.41/IntelliJ IDEA.app/Contents/lib/jps-launcher.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/lib/tools.jar:/Users/richard/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/163.10154.41/IntelliJ IDEA.app/Contents/lib/optimizedFileManager.jar 
2016-12-28 10:59:43,958 [2447923]   INFO - ij.compiler.impl.CompileDriver - COMPILATION STARTED (BUILD PROCESS) 
2016-12-28 10:59:43,960 [2447925]   INFO - j.compiler.server.BuildManager - Using preloaded build process to compile /Users/richard/workspace-scala 
2016-12-28 10:59:44,181 [2448146]  ERROR - .impl.MessageBusConnectionImpl - java.lang.NullPointerException 
java.lang.RuntimeException: java.lang.NullPointerException
    at com.intellij.openapi.application.impl.LaterInvocator.invokeAndWait(LaterInvocator.java:189)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:662)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:667)
    at org.jetbrains.plugins.scala.extensions.package$$anonfun$invokeAndWait$1.apply$mcV$sp(package.scala:567)
    at org.jetbrains.plugins.scala.extensions.package$.preservingControlFlow(package.scala:577)
    at org.jetbrains.plugins.scala.extensions.package$.invokeAndWait(package.scala:566)
    at org.jetbrains.plugins.scala.compiler.ServerMediator$$anon$1.buildStarted(ServerMediator.scala:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:117)
    at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:381)
    at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:368)
    at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:347)
    at com.intellij.util.messages.impl.MessageBusImpl.access$200(MessageBusImpl.java:42)
    at com.intellij.util.messages.impl.MessageBusImpl$2.invoke(MessageBusImpl.java:230)
    at com.sun.proxy.$Proxy117.buildStarted(Unknown Source)
    at com.intellij.compiler.server.BuildManager$NotifyingMessageHandler.buildStarted(BuildManager.java:1435)
    at com.intellij.compiler.server.DelegatingMessageHandler.buildStarted(DelegatingMessageHandler.java:18)
    at com.intellij.compiler.server.DelegatingMessageHandler.buildStarted(DelegatingMessageHandler.java:18)
    at com.intellij.compiler.server.BuildMessageDispatcher.sendBuildParameters(BuildMessageDispatcher.java:115)
    at com.intellij.compiler.server.BuildManager.a(BuildManager.java:724)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.intellij.util.concurrency.BoundedTaskExecutor$2.run(BoundedTaskExecutor.java:210)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at org.jetbrains.plugins.scala.compiler.CompileServerLauncher$$anonfun$15.apply(CompileServerLauncher.scala:282)
    at org.jetbrains.plugins.scala.compiler.CompileServerLauncher$$anonfun$15.apply(CompileServerLauncher.scala:282)
    at scala.collection.TraversableLike$$anonfun$filterImpl$1.apply(TraversableLike.scala:259)
    at scala.collection.immutable.Set$Set3.foreach(Set.scala:145)
    at scala.collection.TraversableLike$class.filterImpl(TraversableLike.scala:258)
    at scala.collection.TraversableLike$class.filter(TraversableLike.scala:270)
    at scala.collection.AbstractTraversable.filter(Traversable.scala:104)
    at org.jetbrains.plugins.scala.compiler.CompileServerLauncher$.org$jetbrains$plugins$scala$compiler$CompileServerLauncher$$jdkChangeRequired(CompileServerLauncher.scala:282)
    at org.jetbrains.plugins.scala.compiler.CompileServerLauncher.start(CompileServerLauncher.scala:56)
    at org.jetbrains.plugins.scala.compiler.CompileServerLauncher.tryToStart(CompileServerLauncher.scala:41)
    at org.jetbrains.plugins.scala.compiler.ServerMediator$$anon$1$$anonfun$buildStarted$2.apply$mcV$sp(ServerMediator.scala:43)
    at org.jetbrains.plugins.scala.extensions.package$$anonfun$invokeAndWait$1$$anon$16.run(package.scala:569)
    at com.intellij.openapi.application.TransactionGuardImpl$6.run(TransactionGuardImpl.java:318)
    at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:166)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.a(LaterInvocator.java:417)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:401)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:843)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:679)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:391)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
2016-12-28 10:59:44,183 [2448148]  ERROR - .impl.MessageBusConnectionImpl - IntelliJ IDEA 2016.3.2  Build #IU-163.10154.41 
2016-12-28 10:59:44,183 [2448148]  ERROR - .impl.MessageBusConnectionImpl - JDK: 1.8.0_112-release 
2016-12-28 10:59:44,183 [2448148]  ERROR - .impl.MessageBusConnectionImpl - VM: OpenJDK 64-Bit Server VM 
2016-12-28 10:59:44,183 [2448148]  ERROR - .impl.MessageBusConnectionImpl - Vendor: JetBrains s.r.o 
2016-12-28 10:59:44,183 [2448148]  ERROR - .impl.MessageBusConnectionImpl - OS: Mac OS X 
2016-12-28 10:59:44,183 [2448148]  ERROR - .impl.MessageBusConnectionImpl - Last Action: CompileDirty 
2016-12-28 10:59:48,828 [2452793]   INFO - lij.compiler.impl.CompilerUtil -     COMPILATION FINISHED (BUILD PROCESS); Errors: 0; warnings: 1 took 4878 ms: 0 min 4sec 

CompileServerLauncher.scala indicates that this is something to do with not being able to find a JDK 8 to use, although if it can't find one it looks like it should fail with an error message, not a NullPointerException.

Dulce answered 3/6, 2016 at 10:47 Comment(4)
Thanks for looking into this, I'm having the same problem (with the same error in the logs) and it's hard to find much information about it. Have you had any more luck with figuring out what's wrong?Wardell
I didn't work it out but I upgraded to IntelliJ 2016.3.5 and after a reboot the Scala compile server is running again. I also upgraded to JDK 1.8.0_112 and Scala 2.12.1. Perhaps one or more of those upgrades helped. It's also worth checking that each of your projects uses JDK 8 and/or Scala 2.12. I have a project for configuration settings that I also configured with Java and Scala SDKs.Dulce
I have my Scala compiler server configured with 1GB of heap RAM and the Java compiler with 2GB. I wondered if the compile server was having trouble allocating its block of RAM. The machine has 16GB and there's usually some spare even with several hefty Java processes running. I don't think it is this, but as the machine goes a long time between reboots perhaps there isn't a big enough block of RAM even if though there is enough free in total?Dulce
One last thought - I wondered if it could be something to do with upgrading to a new version of the JDK. I tend to keep the old JDK on the disk, but sometimes I notice that a project is pointing to an old JDK that isn't installed any more. This might be something to do with my setup as most of my development is on a Mac, but I also have a Linux workstation and coordinate changes via Subversion.Dulce
A
5

I had the same problem, and it was caused by conflicting settings files between the settings repository and the local preferences. Your compile server settings are store in a file called scala.xml in your IDEA preferences dir.

If you use "settings sync", i.e. an online repository to sync your IDEA settings, make sure that you have only one scala.xml config file. Go to your Library/Preferences/<IDEA-Dir>/ and remove that file from the options and settingsRepository dirs. This resets to "factory settings".

Restart IntelliJ, setup the compile server again. It should now only write one file, to the settingsRepository dir, with a new ID and port allocation for the compile server.

This fixed it for me.

Argentina answered 24/1, 2018 at 15:56 Comment(1)
I would have never been able to find the root cause of this if it wasn't for this answer. Thank you! 2024 and still relevant! (and unfixed by Intellij :P)Gallaway
B
2

I faced the same issue when using IntelliJ 2022.3.1.
I noticed that the compiler server working directory seems to change when switching between projects, so it is good to set the project home as the compiler server's default working directory.
Go to:
File -> Settings -> Build,Execution,Deployment -> Compiler -> ScalaCompiler -> ScalaCompileServer,
then check the box "Start process in project directory"

Also, do ensure that -server -Xss1m is included in the JVM VM options:

enter image description here

Brittaney answered 9/1, 2023 at 1:27 Comment(1)
This worked for me until I updated the scala plugin, then it stopped. Jetbrains has had an open ticket for this issue since 2015 that they're ignoring.Supertax
C
0

I still got this issue with IntelliJ 2021.2.2 Community Edition and simple restart of IntelliJ IDE resolved it.

Chiquita answered 19/10, 2021 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.