twitter/finagle

Unable to stop HighResTimer

Open

#756 创建于 2019年2月6日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)Scala (8,864 star) (1,435 fork)batch import
help wanted

描述

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

贡献者指南

Unable to stop HighResTimer · twitter/finagle#756 | Good First Issue