Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Default logger startup interleaves class resolution with logger creation, leaking an already-started logger when a later entry fails

Abierto
#3,687 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
scala

Línea de trabajo

Read actor/src/main/scala/org/apache/pekko/event/Logging.scala around lines 137-159 and 192-209 to see logger creation and teardown. Add a test in actor-tests/src/test/scala/org/apache/pekko/event/LoggerSpec.scala with one valid and one invalid logger. Done means system creation fails with ConfigurationException and the valid logger actor is stopped and unsubscribed.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

Summary

startDefaultLoggers resolves and creates each configured logger inside a single for-comprehension. If entry N cannot be resolved, entries 1..N-1 have already been created as system actors, but the loggers field is only assigned after the whole comprehension succeeds — so the teardown path never sees them.

Evidence

actor/src/main/scala/org/apache/pekko/event/Logging.scala:137-159:

      val myloggers =
        for {
          loggerName <- defaultLoggers
          if loggerName != StandardOutLogger.getClass.getName
        } yield {
          system.dynamicAccess
            .getClassFor[Actor](loggerName)
            .map { actorClass =>
              addLogger(system, actorClass, level, logName)   // creates the actor
            }
            .recover {
              case e =>
                throw new ConfigurationException(
                  "Logger specified in config can't be loaded [" + loggerName +
                  "] due to [" + e.toString + "]", e)
            }
            .get                                              // throws here
        }
      guard.lock()
      try {
        loggers = myloggers                                   // :159 — never reached

addLogger (:216-226) creates the actor and blocks on initialization:

    val actor = system.systemActorOf(Props(clazz).withDispatcher(system.settings.LoggersDispatcher), name)
    implicit def timeout: Timeout = system.settings.LoggerStartTimeout
    ...
      try Await.result(actor ? InitializeLogger(this), timeout.duration)

stopDefaultLoggers (:192-209) iterates the loggers field:

    for {
      logger <- loggers
      if logger != StandardOutLogger
    } {
      // this is very necessary, else you get infinite loop with DeadLetter
      unsubscribe(logger)
      logger match {
        case ref: InternalActorRef => ref.stop()
        case _                     =>
      }
    }

Impact

With pekko.loggers = [<valid>, <invalid>], the valid logger is created as a system actor and initialized, then the ConfigurationException propagates before loggers = myloggers executes. System creation fails, and stopDefaultLoggers iterates a loggers value that does not contain the already-started actor — so it is neither unsubscribed nor stopped. A partially-initialized logging setup outlives the failed ActorSystem creation.

Suggested direction

Resolve every class name first and fail fast before creating any actor, then create the loggers. Alternatively, accumulate successfully-created loggers so the failure path can unsubscribe and stop them.

Test

actor-tests/src/test/scala/org/apache/pekko/event/LoggerSpec.scala — a case configuring one valid plus one unresolvable logger, asserting that system creation fails with ConfigurationException and that the valid logger actor has been stopped and unsubscribed.

Lenguaje dominante
Scala
Estrellas
1.7k
Forks
212
Merge medio
18 h 20 min
PR fusionados (30 d)
108

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/pekko

Todos los issues de apache/pekko

Issues similares

Más issues de Scala

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.