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

NonDaemonThreadLogger and SBT 1.6.x #2745

Closed
mattroberts297 opened this issue Jan 11, 2022 · 2 comments
Closed

NonDaemonThreadLogger and SBT 1.6.x #2745

mattroberts297 opened this issue Jan 11, 2022 · 2 comments
Labels

Comments

@mattroberts297
Copy link

Using SBT 1.6.x the NonDaemonThreadLogger appears to print out SBT-related threads. Reproducible:

Main.scala

import cats.effect.{ExitCode, IO, IOApp}

object Main extends IOApp {
  def run(args: List[String]): IO[ExitCode] = {
    IO(ExitCode.Success)
  }
}

build.sbt

ThisBuild / scalaVersion     := "2.13.7"
ThisBuild / version          := "0.1.0-SNAPSHOT"
ThisBuild / organization     := "com.example"
ThisBuild / organizationName := "example"

lazy val root = (project in file("."))
  .settings(
    name := "sbt-cats-repro",
    libraryDependencies ++= Seq(
      "org.typelevel" %% "cats-effect" % "3.3.4"
    )
  )

project/build.properties

sbt.version=1.6.1

Output:

sbt:sbt-cats-repro> run
[info] running Main
[success] Total time: 1 s, completed 11-Jan-2022 16:44:22
sbt:sbt-cats-repro> Non-daemon threads currently preventing JVM termination: - 175: Thread[com.swoval.files.apple.FileEventsMonitor.runloop,5,main]
 -  - 23: Thread[pool-1-thread-4,5,main]
 -  - 180: Thread[sbt-socket-server,5,main]
 -  - 173: Thread[com.swoval.files.SymlinkWather.callback-executor-1,5,main]
 -  - 181: Thread[com.swoval.files.apple.FileEventsMonitor.callback-1,5,main]
 -  - 22: Thread[pool-1-thread-3,5,main]
 -  - 177: Thread[com.swoval.files.SymlinkWather.callback-executor-1,5,main]
 -  - 176: Thread[com.swoval.files.apple.FileEventsMonitor.runloop,5,main]
 -  - 179: Thread[com.swoval.files.apple.FileEventsMonitor.runloop,5,main]
 -  - 178: Thread[FileTreeRepository-callback-executor-1,5,main]
 -  - 29: Thread[sbt-console-input-reader,5,main]
 -  - 1: Thread[main,5,main]
 -  - 21: Thread[pool-1-thread-2,5,main]
 -  - 19: Thread[pool-1-thread-1,5,main]
 -  - 172: Thread[com.swoval.files.apple.FileEventsMonitor.runloop,5,main]
 -  - 174: Thread[FileTreeRepository-callback-executor-1,5,main]
 -  - 24: Thread[pool-1-thread-5,5,main]
 -  - 193: Thread[com.swoval.files.apple.FileEventsMonitor.callback-1,5,main]

I suspect this issue is now observable due to this SBT change: sbt/sbt#6665. Though when I attached a debugger to SBT 1.5.x I observed that the NonDaemonThreadLogger is terminated before it gets to detectThreads(), so perhaps this has always been an issue, but just not observable.

@djspiewak
Copy link
Member

Yeah I think this has always been an issue, just not observable. The NonDaemonThreadLogger shouldn't be run in an unforked sbt run. It just doesn't have any meaning in that context, and it's not useful anyway because sbt's thread cleaner will take a wrecking ball to all of that anyway. Seeing as we now have the ability to detect this scenario, we just shouldn't run the logger in that case.

Quick workaround while we get to a fix: run / fork := true. This will also fix other issues since unforked runs really don't work very well in sbt anymore (e.g. ctrl-c works perfectly in Cats Effect in every case except unforked sbt, simply because unforked sbt has an unresolved bug which prevents it from forwarding the interrupt).

@mattroberts297
Copy link
Author

Thank you @djspiewak and @vasilmkd 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants