question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When using Http4sClient on Cornichon 1.7.0 exception is thrown: "toMillis not allowed on infinite Durations"

See original GitHub issue

Cornichon 1.7.0

When using experimental Http4sClient by setting config:

useExperimentalHttp4sClient = true

following exception is thrown when running tests:

2019/04/02 18:11:31 DEBUG[text-global-788] org.http4s.client.PoolManager - Requesting connection: curAllocated=0 idleQueues.size=0 waitQueue.size=0 maxWaitQueueLimit=500 closed=false
2019/04/02 18:11:31 DEBUG[text-global-788] org.http4s.client.PoolManager - Active connection not found. Creating new one. curAllocated=0 idleQueues.size=0 waitQueue.size=0 maxWaitQueueLimit=500 closed=false
2019/04/02 18:11:31 DEBUG[text-global-785] org.http4s.blaze.channel.nio2.ByteBufferHead - Starting up.
2019/04/02 18:11:31 DEBUG[text-global-785] org.http4s.blaze.channel.nio2.ByteBufferHead - Stage ByteBufferHead sending inbound command: Connected
2019/04/02 18:11:31 DEBUG[text-global-785] org.http4s.client.blaze.ReadBufferStage - Stage started up. Beginning read buffering
2019/04/02 18:11:31 DEBUG[text-global-785] org.http4s.client.blaze.ReadBufferStage - Stage ReadBufferStage sending inbound command: Connected
2019/04/02 18:11:31 DEBUG[text-global-785] org.http4s.client.blaze.Http1Connection - Starting up.
2019/04/02 18:11:31 DEBUG[text-global-790] org.http4s.blazecore.ResponseHeaderTimeoutStage - Starting up.
java.lang.IllegalArgumentException: toMillis not allowed on infinite Durations
	at scala.concurrent.duration.Duration$Infinite.fail(Duration.scala:213)
	at scala.concurrent.duration.Duration$Infinite.toMillis(Duration.scala:218)
	at org.http4s.blazecore.ResponseHeaderTimeoutStage.stageStartup(ResponseHeaderTimeoutStage.scala:55)
	at org.http4s.blazecore.ResponseHeaderTimeoutStage.init(ResponseHeaderTimeoutStage.scala:60)
	at org.http4s.client.blaze.BlazeClient$.$anonfun$makeClient$21(BlazeClient.scala:128)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:81)
	at monix.eval.Task$.unsafeStartNow(Task.scala:4249)
	at monix.eval.internal.TaskCreate$.$anonfun$asyncF$1(TaskCreate.scala:150)
	at monix.eval.internal.TaskCreate$.$anonfun$asyncF$1$adapted(TaskCreate.scala:140)
	at monix.eval.internal.TaskRestartCallback.start(TaskRestartCallback.scala:58)
	at monix.eval.internal.TaskRunLoop$.executeAsyncTask(TaskRunLoop.scala:564)
	at monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:115)
	at monix.eval.Task$.unsafeStartNow(Task.scala:4249)
	at monix.eval.internal.TaskBracket$BaseStart$$anon$1.onSuccess(TaskBracket.scala:143)
	at monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:143)
	at monix.eval.Task$.unsafeStartNow(Task.scala:4249)
	at monix.eval.internal.TaskBracket$BaseStart.apply(TaskBracket.scala:131)
	at monix.eval.internal.TaskBracket$BaseStart.apply(TaskBracket.scala:121)
	at monix.eval.internal.TaskRestartCallback.run(TaskRestartCallback.scala:65)
	at monix.execution.internal.Trampoline.monix$execution$internal$Trampoline$$immediateLoop(Trampoline.scala:66)
	at monix.execution.internal.Trampoline.startLoop(Trampoline.scala:32)
	at monix.execution.schedulers.TrampolineExecutionContext$JVMOptimalTrampoline.startLoop(TrampolineExecutionContext.scala:146)
	at monix.execution.internal.Trampoline.execute(Trampoline.scala:39)
	at monix.execution.schedulers.TrampolineExecutionContext.execute(TrampolineExecutionContext.scala:65)
	at monix.execution.schedulers.BatchingScheduler.execute(BatchingScheduler.scala:50)
	at monix.execution.schedulers.BatchingScheduler.execute$(BatchingScheduler.scala:47)
	at monix.execution.schedulers.AsyncScheduler.execute(AsyncScheduler.scala:29)
	at monix.eval.internal.TaskRestartCallback.start(TaskRestartCallback.scala:56)
	at monix.eval.internal.TaskRunLoop$.executeAsyncTask(TaskRunLoop.scala:564)
	at monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:115)
	at monix.eval.internal.TaskRunLoop$.$anonfun$restartAsync$1(TaskRunLoop.scala:192)
	at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:140)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

The problem occurs only if logging level is set to DEBUG, because the problematic line from file ResponseHeaderTimeoutStage.scala:55 is:

logger.debug(s"Starting response header timeout stage with timeout of ${timeout.toMillis} ms")

When setting log level to INFO everything works fine.

I think that reason for this is setting Duration.Inf when creating BlazeClientBuilder in Http4sClient.scala:

private val (httpClient, safeShutdown) =
    BlazeClientBuilder(executionContext = ec)
      .withoutSslContext
      .withMaxTotalConnections(300)
      .withMaxWaitQueueLimit(500)
      .withIdleTimeout(Duration.Inf)
      .withResponseHeaderTimeout(Duration.Inf)
      .withRequestTimeout(Duration.Inf)
      .allocated
      .runSyncUnsafe(10.seconds)

Is my guess correct? 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
karolzmudacommented, Apr 3, 2019

We’ve managed to apply workaround by setting log level to INFO which got our tests running correctly again, so it is not that urgent 😉

0reactions
karolzmudacommented, May 7, 2019

Thank you, we will bump the version in our dependencies.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP client hangs with an infinite loop when an exception is ...
HTTP client hangs with an infinite loop when an exception is thrown in the SSL Context when the server presents an unknown certificat......
Read more >
HTTP Client - http4s
Let's create a client with http4s to try our service. ... The following lines are not necessary if you are in an [...
Read more >
Using as an http4s client — tapir 0.x documentation
Response parser throws an exception if decoding of the result fails. I => (org.http4s.Request[F], org.http4s.Response[F] => F[Either[E, O]]).
Read more >
Scala project from scratch #2 - http4s, tapir, long fixes for ...
Second episode of the series in which I'm making a full app in functional Scala! This one is a little longer because I...
Read more >
HTTP4s increase max upload size - Stack Overflow
can you try changing content length in headers? eg: content-length: 3495 OR Content-Length: 3495 depending on size of your content.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found