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

Fixes #4084 Port jetty to cats effect 3 #4191

Merged
merged 8 commits into from Jan 16, 2021
Merged

Fixes #4084 Port jetty to cats effect 3 #4191

merged 8 commits into from Jan 16, 2021

Conversation

ashwinbhaskar
Copy link
Collaborator

No description provided.

@ashwinbhaskar
Copy link
Collaborator Author

@rossabaker The tests in JettyServerSuite all time out after 30 seconds and result in error. Where did I go wrong in that?

import org.eclipse.jetty.server.{HttpConfiguration, HttpConnectionFactory, Server, ServerConnector}
import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
import org.http4s.dsl.io._
import org.http4s.servlet.AsyncHttp4sServlet
import org.http4s.syntax.all._

object Issue454 {
implicit val cs: ContextShift[IO] = Http4sSpec.TestContextShift
// implicit val cs: ContextShift[IO] = Http4sSpec.TestContextShift
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't ever run as part of the build. If we can't figure out a way to automate it, then I think it's ready to be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it

@@ -224,7 +233,8 @@ sealed class JettyBuilder[F[_]] private (
service = service,
asyncTimeout = builder.asyncTimeout,
servletIo = builder.servletIo,
serviceErrorHandler = builder.serviceErrorHandler
serviceErrorHandler = builder.serviceErrorHandler,
dispatcher
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other backends are creating dispatcher in Resource, which is a pattern I like. The challenge would be how you can thread it down to here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you suggesting to pass Resource[IO,Dispatcher[IO]] instead of Dispatcher[IO] ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm saying to let one of the functions in this create it. In BlazeClientBuilder (yes, that's a client, and this is a server, but... almost the same), we're creating and using a dispatcher resource in the .resource function. Can we do that here?

I think if the function in the Mount class took a Dispatcher, the rest of it would fall into place, and you could remove the Dispatcher as a parameter of the builder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, let me try that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rossabaker the resource method returns a Resource with type parameter F. That means we should have a Dispatcher[F] in scope. We can change the signature of def resource: Resource[F, Server] to def resource(dispatcher: Dispatcher[F]): Resource[F, Server]. But this would mean changing the signature on the trait ServerBuilder.
If we want to avoid this, then we would have to pass a dispatcher to the builder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was thinking that resource would create a Dispatcher resource and flatMap it. BlazeClientBuilder does it like this:

  def resource: Resource[F, Client[F]] =
    for {
      dispatcher <- Dispatcher[F]
      ...
    } yield ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rossabaker my bad. You are right. Having an implicit Async[F] brings Dispatcher[F] in scope

@rossabaker
Copy link
Member

Are we past the timeout problem now?

@ashwinbhaskar
Copy link
Collaborator Author

Are we past the timeout problem now?

@rossabaker no, the timeout issue still persists.

@rossabaker
Copy link
Member

Oh, the module just isn't enabled yet. I didn't see the failing test and was hoping we were through it. Do you have any ideas yet or do you need some help?

@ashwinbhaskar
Copy link
Collaborator Author

Oh, the module just isn't enabled yet. I didn't see the failing test and was hoping we were through it. Do you have any ideas yet or do you need some help?

I am still trying to figure out the issue. Any help is welcome:)
I am also skeptical of the changes made in Issue454.scala. I think the dispatcher will be shutdown well AsyncHttp4sServlet gets a change to use it?

@rossabaker rossabaker added this to To do in Cats Effect 3 via automation Jan 13, 2021
@rossabaker
Copy link
Member

Oh, I thought we were deleting Issue454 entirely since it isn't a test that gets run.

@ashwinbhaskar
Copy link
Collaborator Author

Oh, I thought we were deleting Issue454 entirely since it isn't a test that gets run.

okay, I understood it as deleting the implicit line 😅
Will delete it:)

@ashwinbhaskar
Copy link
Collaborator Author

Added some log statements. It confirms this line is causing the timeout.

@rossabaker
Copy link
Member

Try unsafeRunAndForget instead of unsafeRunSync.

@ashwinbhaskar
Copy link
Collaborator Author

ashwinbhaskar commented Jan 13, 2021

Try unsafeRunAndForget instead of unsafeRunSync.

results in IOException: Server returned HTTP response code: 503..

@ashwinbhaskar ashwinbhaskar changed the title WIP Fixes #4084 Port jetty to cats effect 3 Fixes #4084 Port jetty to cats effect 3 Jan 13, 2021
@ashwinbhaskar
Copy link
Collaborator Author

@rossabaker The issue was in servlet module. async_ has signature k: (Either[Throwable, A] => Unit) => Unit): F[A] but Deferred's complete was returning an F[Boolean].

@@ -82,7 +82,8 @@ class AsyncHttp4sServlet[F[_]](

val timeout =
F.async_[Response[F]] { cb =>
val _ = gate.complete(ctx.addListener(new AsyncTimeoutHandler(cb)))
val _ =
dispatcher.unsafeRunSync(gate.complete(ctx.addListener(new AsyncTimeoutHandler(cb))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to block here you should be able to just do

        F.async[Response[F]] { cb =>
          gate.complete(ctx.addListener(new AsyncTimeoutHandler(cb))).as(Option.empty[F[Unit]])
        }

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@rossabaker rossabaker merged commit 0e0f74b into http4s:main Jan 16, 2021
Cats Effect 3 automation moved this from To do to Done Jan 16, 2021
rossabaker added a commit to http4s/http4s-servlet that referenced this pull request Apr 3, 2022
rossabaker added a commit to http4s/http4s-servlet that referenced this pull request Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants