Skip to content

Unable to stop HighResTimer #756

@dani-e-l

Description

@dani-e-l

Hello we are using Finagle as a HttpClient - it works really good. Great job.

Unfortunately Finagle generates resource leak under standard behavior that applications are deployed and undeployed many times on JBoss AS, Tomcat etc.
By resource leak I mean that if I 100 times deploy and undeploy an application that uses Finagle I'll get at least 100 threads

The problem is that finagle contains unstopable threads

Problem is withh HighResTimer Thread
There is no possibility to stop it using Finagle API.

object HighResTimer {

  /**
   * The default Timer used for configuration.
   *
   * It is a shared resource and as such, `stop` is ignored.
   */
  val Default: com.twitter.util.Timer =
    new JavaTimer(true, Some("HighResTimer")) {
      override def stop(): Unit = ()
    }

Unfortunately we can't use our own HighResTimer using params because Default is initialized when Http.client is created and there are two instances

 /**
   * Retries failures that are guaranteed to be safe to retry
   * (see [[RetryPolicy.RetryableWriteException]]).
   */
  private[finagle] def moduleRequeueable[Req, Rep]: Stackable[ServiceFactory[Req, Rep]] =
    new Stack.Module[ServiceFactory[Req, Rep]] {
      def role: Stack.Role = Retries.Role

      def description: String =
        "Retries requests, at the service application level, that have been rejected"

      val parameters = Seq(
        implicitly[Stack.Param[Stats]],
        implicitly[Stack.Param[Budget]],
        implicitly[Stack.Param[HighResTimer]]
      )

There are two alternative solutions

  1. possibility to stop this Thread
  2. Do not instantiate HighResTimer when Client is created

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions