Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen function is timing out after 45 sec. #120

Closed
pradeepcheers opened this issue May 17, 2023 · 14 comments · Fixed by #121
Closed

Listen function is timing out after 45 sec. #120

pradeepcheers opened this issue May 17, 2023 · 14 comments · Fixed by #121

Comments

@pradeepcheers
Copy link

pradeepcheers commented May 17, 2023

I'm trying to listen to K8s nodes / pods continuously but the listen function times out after 45 seconds. Is this the expected behaviour? Is there a way to listen indefinitely and print the any new nodes are added to the cluster?

Timeout Exception:

java.util.concurrent.TimeoutException: 45 seconds
        at timeout @ org.http4s.ember.core.Util$.timeoutMaybe(Util.scala:104)
        at main$ @ poc.k8s.ControllerTest$.main(ControllerTest.scala:24)
        at timeout @ org.http4s.ember.core.Util$.timeoutMaybe(Util.scala:104)
        at timeout @ org.http4s.ember.core.Util$.timeoutMaybe(Util.scala:104)

Code:

object ControllerTest extends IOApp:

  val clientResource = EmberKubernetesClient.defaultConfig[IO, Json]

  def run(args: List[String]): IO[ExitCode] =
    for {
      _ <- IO.println("Watch K8s nodes")

      watchNodes <- fs2.Stream.resource(clientResource)
        .flatMap(APIs.nodes.list().listen)
        // Debugging
        .flatMap(ev =>
          exec(
            IO.println("event => " + ev.event) >> 
            IO.println("name => " + ev.payload.metadata.flatMap(_.name))
          )
        )
        .compile
        .drain

    } yield ExitCode.Succes

@hnaderi Could you help with this please? Thanks

@hnaderi
Copy link
Owner

hnaderi commented May 17, 2023

Hi 👋
That's the default timeout for http4s ember client which is not exposed in the kubernetes client builder currently (v0.11.x),
However is exposed in the current development version (v0.12.0) which is not yet released.
As a workaround you can use the .fromClient method and pass any http4s client directly, however you'll need to setup TLS context manually.
I can release a snapshot version of the development version, let me know if it helps you.

@hnaderi
Copy link
Owner

hnaderi commented May 17, 2023

Also another workaround would be to long poll using the current version, i.e. listen and continue next listen from last offset.
However, the new version will have been released at most by this weekend.

@pradeepcheers
Copy link
Author

@hnaderi Let me check the options you suggested and get back to you. Thanks

@pradeepcheers
Copy link
Author

Also another workaround would be to long poll using the current version, i.e. listen and continue next listen from last offset.

Do you have any example to do this some where? I can't figure out how to trigger next listen from the last offset. Thanks

@hnaderi
Copy link
Owner

hnaderi commented May 17, 2023

Also another workaround would be to long poll using the current version, i.e. listen and continue next listen from last offset.

Do you have any example to do this some where? I can't figure out how to trigger next listen from the last offset. Thanks

You can see here to figure out watch semantics. Basically you need to pass required arguments to the list method, i.e. .list(continue = Some("last token")).
Also, I'll publish a snapshot version with all the client configs exposed to the user tonight, after my work day finishes.

@hnaderi
Copy link
Owner

hnaderi commented May 17, 2023

@pradeepcheers This will publish a snapshot, you can use it by:

ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("snapshots")
libraryDependencies ++= Seq(
  "dev.hnaderi" %% "scala-k8s-http4s-ember" % "0.12-706250c-SNAPSHOT"
)

And you can change timeout like this:

EmberKubernetesClient(
  EmberClientBuilder.default[IO].withTimeout(Duration.Inf)
).defaultConfig[Json]

Edit: CI has failed, I will fix the problem and republish tomorrow.

@hnaderi
Copy link
Owner

hnaderi commented May 18, 2023

@pradeepcheers You can try this version 0.12-f3fc096-SNAPSHOT

@pradeepcheers
Copy link
Author

@hnaderi Thanks. However getting similar timeout exception in a different place this time!

[error] java.util.concurrent.TimeoutException: 45 seconds
[error] 	at timeout$extension @ org.http4s.ember.client.internal.ClientHelpers$.writeRead$1(ClientHelpers.scala:171
[error] 	at main$ @ poc.k8s.ControllerTest$.main(ControllerTest.scala:28)
[error] 	at timeout$extension @ org.http4s.ember.client.internal.ClientHelpers$.writeRead$1(ClientHelpers.scala:171
[error] 	at timeout$extension @ org.http4s.ember.client.internal.ClientHelpers$.writeRead$1(ClientHelpers.scala:171
[error] stack trace is suppressed; run last controller / Compile / run for the full output
[error] (controller / Compile / run) java.util.concurrent.TimeoutException: 45 seconds
[error] Total time: 51 s, completed 18 May 2023, 10:33:20

@hnaderi
Copy link
Owner

hnaderi commented May 18, 2023

EmberKubernetesClient(
  EmberClientBuilder.default[IO].withTimeout(Duration.Inf)
).defaultConfig[Json]

Have you changed the client to this?
If that's the case it might be some problem on the ember side, as scala-k8s doesn't impose any timeout or stuff like that

@hnaderi
Copy link
Owner

hnaderi commented May 18, 2023

@pradeepcheers I filed an issue on the http4s for this behavior here
In the meanwhile, you can use other http4s clients, like jdk-client, netty or blaze.

@hnaderi
Copy link
Owner

hnaderi commented May 18, 2023

@pradeepcheers Apparently the example I gave you was not complete, you need to also add
.withIdleConnectionTime(Duration.Inf)

EmberKubernetesClient(
  EmberClientBuilder.default[IO]
    .withTimeout(Duration.Inf)
    .withIdleConnectionTime(Duration.Inf)
).defaultConfig[Json]

@pradeepcheers
Copy link
Author

@hnaderi sorry was a bit busy earlier. Let me try what you suggested above, I will keep you posted. I really appreciate your help. Thanks

@pradeepcheers
Copy link
Author

pradeepcheers commented May 19, 2023

@pradeepcheers Apparently the example I gave you was not complete, you need to also add .withIdleConnectionTime(Duration.Inf)

EmberKubernetesClient(
  EmberClientBuilder.default[IO]
    .withTimeout(Duration.Inf)
    .withIdleConnectionTime(Duration.Inf)
).defaultConfig[Json]

@hnaderi the listen function works as expected with the above change. Thanks a lot

@hnaderi
Copy link
Owner

hnaderi commented May 19, 2023

This changes are released in https://github.com/hnaderi/scala-k8s/releases/tag/v0.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants