I did a little digging here and found the cause.
I don't use sys.exit() to exit the scala console and haven't tested what
happens there. I wouldn't know if high cpu usage in this scenario is a
regression or not.
The console exit method that Dispatch tries to support is ctrl+d or
:quit . This has regressed with sbt 0.13.1. The console fails to close,
as it does if any threads are still running.
The problem is here:
https://github.com/dispatch/reboot/blob/d7c5fb54aa86c7bebf73ff4921e5c03b1c268f59/core/src/main/scala/defaults.scala#L20-L23
Dispatch tries to determine if it's running inside an sbt console, and
if so, it uses a thread-pool configuration that calls the global
shutdown() when interrupted. We don't want this behavior in environments
outside sbt.
Dispatch knows it's in sbt if the current thread group's name is
"trap.exit". But in 0.13.1, this is no longer the case:
scala> Thread.currentThread.getThreadGroup.getName
res0: String = run-main-group-0
So Dispatch doesn't know it's in sbt and doesn't make those
accommodations. If you want to exit cleanly, you'll need to call
Http.shutdown() before :quit
Is there a better way I can know that we're in a Scala console inside
sbt, which will work for all sbt versions 0.12.x and 0.13.x ?
Nathan
On 04/21/2014 12:10 AM, eugene yokota wrote:
> That is definitely a possibility. Here is a comment from [a suspect
> commit][2], which happened after sbt 0.13.0.
>
> +/** Wait for all non-daemon threads for `app` to exit, for an
> exception to be thrown in the main thread,
> +* or for `System.exit` to be called in a thread started by `app`. */
> +private[this] def finish(app: App, log: Logger): Int =
>
> After http.shutdown, would there still be some daemons running around?
> If so it could explain the infinite-loop-like behavior as sbt turns
> MacBook Pro into a hot plate.
>
> -eugene
>
>
> [2]:
https://github.com/sbt/sbt/commit/60426facba697b24d0d3d490f48525cdefc79daf
>
> On Sunday, April 20, 2014 11:50:05 PM UTC-4, n8han wrote:
>
> On 04/20/2014 11:48 PM, eugene yokota wrote:
> > console can exit fine on sbt 0.13.0, but on 0.13.1 and 0.13.2 the
> issue
> > is back.
>
> Maybe we should file a bug with sbt? ;)
>
> --
> You received this message because you are subscribed to the Google
> Groups "Dispatch" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
dispatch-scal...@googlegroups.com
> <mailto:
dispatch-scal...@googlegroups.com>.
> For more options, visit
https://groups.google.com/d/optout.