Skip to content

Commit

Permalink
fix #1887
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Apr 3, 2024
1 parent 129e938 commit c4191be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 8 additions & 4 deletions otoroshi/app/utils/letsencrypt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import otoroshi.events.{Alerts, CertRenewalAlert}
import otoroshi.ssl.DynamicSSLEngineProvider.base64Decode
import otoroshi.ssl.{Cert, PemHeaders}
import otoroshi.utils.RegexPool
import otoroshi.utils.syntax.implicits.BetterFiniteDuration
import play.api.Logger
import play.api.libs.json._

Expand Down Expand Up @@ -309,8 +310,11 @@ object LetsEncryptHelper {
s"${env.storageRoot}:letsencrypt:challenges:$domain:${challenge.getToken}",
ByteString(challenge.getAuthorization),
Some(10.minutes.toMillis)
)
authorizeOrder(domain, authorization.getStatus, challenge)
).flatMap { _ =>
3.seconds.timeout.flatMap { _ =>
authorizeOrder(domain, authorization.getStatus, challenge)
}
}
}
.toMat(Sink.seq)(Keep.right)
.run()
Expand All @@ -333,7 +337,7 @@ object LetsEncryptHelper {
} else {
challenge.trigger()
Source
.tick(1.seconds, 3.seconds, ())
.tick(3.seconds, 3.seconds, ())
.mapAsync(1) { _ =>
Future {
challenge.update()
Expand Down Expand Up @@ -364,7 +368,7 @@ object LetsEncryptHelper {
order.execute(csr)
}(blockingEc).flatMap { _ =>
Source
.tick(1.seconds, 5.seconds, ())
.tick(3.seconds, 5.seconds, ())
.mapAsync(1) { _ =>
Future {
order.update()
Expand Down
13 changes: 12 additions & 1 deletion otoroshi/app/utils/syntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.auth0.jwt.interfaces.DecodedJWT
import com.github.blemale.scaffeine.Cache
import com.typesafe.config.{ConfigFactory, ConfigRenderOptions}
import org.apache.commons.codec.binary.{Base64, Hex}
import otoroshi.env.Env
import otoroshi.models.WSProxyServerJson
import otoroshi.next.utils.JsonHelpers
import otoroshi.ssl.DynamicSSLEngineProvider
Expand All @@ -28,7 +29,7 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.{AtomicInteger, AtomicLong, AtomicReference}
import scala.collection.TraversableOnce
import scala.collection.concurrent.TrieMap
import scala.concurrent.duration.Duration
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
import scala.reflect.ClassTag
import scala.util.control.{NoStackTrace, NonFatal}
Expand Down Expand Up @@ -595,6 +596,16 @@ object implicits {
}
}
}
implicit class BetterFiniteDuration(val duration: FiniteDuration) extends AnyVal {
def timeout(implicit env: Env, ec: ExecutionContext): Future[Unit] = await(env, ec)
def await(implicit env: Env, ec: ExecutionContext): Future[Unit] = {
val promise = Promise.apply[Unit]()
env.otoroshiScheduler.scheduleOnce(duration) {
promise.trySuccess(())
}
promise.future
}
}
implicit class BetterDuration(val duration: Duration) extends AnyVal {
final def toHumanReadable: String = {
val units = Seq(
Expand Down

0 comments on commit c4191be

Please sign in to comment.