Fix Logging Service Preventing Normal Shutdown (#1377)

This commit is contained in:
Radosław Waśko 2020-12-30 12:49:56 +01:00 committed by GitHub
parent 9083b90c52
commit 322a967cda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 7 deletions

View File

@ -0,0 +1,7 @@
package org.enso.loggingservice
case class LoggingServiceAlreadyInitializedException()
extends RuntimeException(
"The logging service was already initialized. " +
"If it should be restarted, it should be torn down first."
)

View File

@ -1,7 +1,7 @@
package org.enso.loggingservice
import org.enso.loggingservice.internal.service.{Client, Local, Server, Service}
import org.enso.loggingservice.internal._
import org.enso.loggingservice.internal.service.{Client, Local, Server, Service}
import org.enso.loggingservice.printers.{Printer, StderrPrinter}
import scala.concurrent.{ExecutionContext, Future}
@ -168,9 +168,7 @@ object LoggingServiceManager {
): InitializationResult = {
this.synchronized {
if (currentService.isDefined) {
throw new IllegalStateException(
"The logging service has already been set up."
)
throw new LoggingServiceAlreadyInitializedException()
}
val (service, result): (Service, InitializationResult) = mode match {

View File

@ -11,8 +11,8 @@ import org.enso.loggingservice.printers.{
StderrPrinterWithColors
}
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
import scala.concurrent.duration.DurationInt
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
import scala.util.control.NonFatal
import scala.util.{Failure, Success}
@ -145,6 +145,12 @@ abstract class LoggingServiceSetupHelper(implicit
LoggingServiceManager
.setup(LoggerMode.Server(createPrinters()), logLevel)
.onComplete {
case Failure(LoggingServiceAlreadyInitializedException()) =>
logger.warn(
"Failed to initialize the logger because the logging service " +
"was already initialized."
)
loggingServiceEndpointPromise.trySuccess(None)
case Failure(exception) =>
logger.error(
s"Failed to initialize the logging service server: $exception",
@ -158,6 +164,12 @@ abstract class LoggingServiceSetupHelper(implicit
logLevel
)
.onComplete {
case Failure(LoggingServiceAlreadyInitializedException()) =>
logger.warn(
"Failed to initialize the fallback logger because the " +
"logging service was already initialized."
)
loggingServiceEndpointPromise.trySuccess(None)
case Failure(fallbackException) =>
System.err.println(
s"Failed to initialize the fallback logger: " +

View File

@ -40,7 +40,7 @@ trait ServiceWithActorSystem extends Service {
val loggers: java.lang.Iterable[String] =
Seq("akka.event.Logging$StandardOutLogger").asJava
val config = ConfigFactory
.load()
.empty()
.withValue("akka.loggers", ConfigValueFactory.fromAnyRef(loggers))
.withValue(
"akka.logging-filter",
@ -51,6 +51,7 @@ trait ServiceWithActorSystem extends Service {
"akka.coordinated-shutdown.run-by-actor-system-terminate",
ConfigValueFactory.fromAnyRef("off")
)
.withValue("akka.daemonic", ConfigValueFactory.fromAnyRef("on"))
ActorSystem(
name,
config,

View File

@ -1,11 +1,11 @@
package org.enso.loggingservice.internal.service
import org.enso.loggingservice.LogLevel
import org.enso.loggingservice.internal.protocol.WSLogMessage
import org.enso.loggingservice.internal.{
BlockingConsumerMessageQueue,
InternalLogger
}
import org.enso.loggingservice.internal.protocol.WSLogMessage
import scala.util.control.NonFatal
@ -47,6 +47,8 @@ trait ThreadProcessingService extends Service {
}
val thread = new Thread(() => runQueue())
thread.setName("logging-service-processing-thread")
thread.setDaemon(true)
queueThread = Some(thread)
thread.start()
}