<commit_before>package com.twitter.finagle.service

import com.twitter.conversions.time._
import com.twitter.finagle._
import com.twitter.finagle.client.Transporter
import com.twitter.finagle.stats.StatsReceiver
import com.twitter.finagle.util.{DefaultLogger, Updater}
import com.twitter.logging.Level
import com.twitter.util.{Future, Duration, Time, Throw, Return, Timer, TimerTask}
import java.util.logging.Logger

object FailFastFactory {
  private sealed trait State
  private case object Ok extends State
  private case class Retrying(
      since: Time,
      task: TimerTask,
      ntries: Int,
      backoffs: Stream[Duration])
    extends State

  private val url = "https://twitter.github.io/finagle/guide/FAQ.html#why-do-clients-see-com-twitter-finagle-failedfastexception-s"

  private object Observation extends Enumeration {
    type t = Value
    val Success, Fail, Timeout, TimeoutFail, Close = Value
  }

  private val defaultBackoffs: Stream[Duration] = Backoff.exponentialJittered(1.second, 32.seconds)

  val role = Stack.Role("FailFast")

  /**
   * For details on why clients see [[FailedFastException]]s see the
   * [[https://twitter.github.io/finagle/guide/FAQ.html#why-do-clients-see-com-twitter-finagle-failedfastexception-s FAQ]]
   *
   * @see The [[https://twitter.github.io/finagle/guide/Clients.html#fail-fast user guide]]
   *      for more details.
   */
  case class FailFast(enabled: Boolean) {
    def mk(): (FailFast, Stack.Param[FailFast]) =
      (this, FailFast.param)
  }
  object FailFast {
    implicit val param = Stack.Param(FailFast(enabled = true))
  }

  /**
   * Creates a [[com.twitter.finagle.Stackable]] [[FailFastFactory]] when enabled.
   */
  def module[Req, Rep]: Stackable[ServiceFactory[Req, Rep]] =
    new Stack.Module6[
      FailFast,
      param.Stats,<commit_msg>finagle-core: Prevent unbounded memory leak from FailFastFactory<commit_after>package com.twitter.finagle.service

import com.twitter.conversions.time._
import com.twitter.finagle._
import com.twitter.finagle.client.Transporter
import com.twitter.finagle.stats.StatsReceiver
import com.twitter.finagle.util.{DefaultLogger, Updater}
import com.twitter.logging.Level
import com.twitter.util.{Future, Duration, Time, Throw, Return, Timer, TimerTask}
import java.util.logging.Logger

object FailFastFactory {
  private sealed trait State
  private case object Ok extends State
  private case class Retrying(
      since: Time,
      task: TimerTask,
      ntries: Int,
      backoffs: Stream[Duration])
    extends State

  private val url = "https://twitter.github.io/finagle/guide/FAQ.html#why-do-clients-see-com-twitter-finagle-failedfastexception-s"

  private object Observation extends Enumeration {
    type t = Value
    val Success, Fail, Timeout, TimeoutFail, Close = Value
  }

  // put a reasonably sized cap on the number of jittered backoffs so that a
  // "permanently" dead host doesn't create a space leak. since each new backoff
  // that is taken will be held onto by this global Stream (having the trailing
  // `constant` avoids this issue).
  private val defaultBackoffs: Stream[Duration] =
    Backoff.exponentialJittered(1.second, 32.seconds).take(16) ++ Backoff.constant(32.seconds)

  val role = Stack.Role("FailFast")

  /**
   * For details on why clients see [[FailedFastException]]s see the
   * [[https://twitter.github.io/finagle/guide/FAQ.html#why-do-clients-see-com-twitter-finagle-failedfastexception-s FAQ]]
   *
   * @see The [[https://twitter.github.io/finagle/guide/Clients.html#fail-fast user guide]]
   *      for more details.
   */
  case class FailFast(enabled: Boolean) {
    def mk(): (FailFast, Stack.Param[FailFast]) =
      (this, FailFast.param)
  }
  object FailFast {
    implicit val param = Stack.Param(FailFast(enabled = true))
  }

  /**
   * Creates a [[com.twitter.finagle.Stackable]] [[FailFastFactory]] when enabled.
   */
  def module[Req, Rep]: Stackable[ServiceFactory[Req, Rep]] =
    new Stack.Module6[
      FailFast,
      param.Stats,
{'fraction_non_alphanumeric': 0.11425732737208147, 'fraction_numerical': 0.0029806259314456036, 'mean_word_length': 3.799761620977354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5328219', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1241, 'n_words': 310}