sbtwindows-subsystem-for-linux

"sbt server is already booting." error when launching sbt from wsl2 ubuntu


I've installed sbt using sdkman on wsl2 ubuntu setup. Currently sbt 1.4.2 is installed. When I try to launch it from the terminal it gives sbt server is already booting. Create a new server? y/n (default y) if I choose n, nothing happens. If I choose y, then sbt starts. What I want to do is to be able to start sbt without that error message. Because this behaviour breaks metals on visual studio code.

I checked the sbt source code and found that the method below prints the error message - in sbt/main/src/main/scala/sbt/Main.scala

private def getSocketOrExit(
      configuration: xsbti.AppConfiguration
  ): (Option[BootServerSocket], Option[Exit]) =
    try (Some(new BootServerSocket(configuration)) -> None)
    catch {
      case _: ServerAlreadyBootingException
          if System.console != null && !ITerminal.startedByRemoteClient =>
        println("sbt server is already booting. Create a new server? y/n (default y)")
        val exit = ITerminal.get.withRawInput(System.in.read) match {
          case 110 => Some(Exit(1))
          case _   => None
        }
        (None, exit)
      case _: ServerAlreadyBootingException =>
        if (SysProp.forceServerStart) (None, None)
        else (None, Some(Exit(2)))
    }
}

So, calling new BootServerSocket(configuration) throws an exception. Exception source is the method below from BootServerSocket.java;

static ServerSocket newSocket(final String sock) throws ServerAlreadyBootingException {
    ServerSocket socket = null;
    String name = socketName(sock);
    try {
      if (!isWindows) Files.deleteIfExists(Paths.get(sock));
      socket =
          isWindows
              ? new Win32NamedPipeServerSocket(name, false, Win32SecurityLevel.OWNER_DACL)
              : new UnixDomainServerSocket(name);
      return socket;
    } catch (final IOException e) {
      throw new ServerAlreadyBootingException();
    }
  }

I checked the isWindows method and it returns false. So the new UnixDomainServerSocket(name) part is running. And somehow it can't create a unix domain server socket. That's all I found out. Is there a way to fix this? Or is this a bug?


Solution

  • After moving my project files to a directory within wsl2, problem is solved. My project files were in a Windows directory before.