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
Ember server graceful shutdown #4179
Ember server graceful shutdown #4179
Conversation
examples/ember/src/main/scala/com/example/http4s/ember/EmberServerSimpleExample.scala
Outdated
Show resolved
Hide resolved
// one run. I think we can write a custom combinator that achieves both | ||
sg.server[F](bindAddress, additionalSocketOptions = additionalSocketOptions) | ||
.interruptWhen(shutdown.signal.attempt) | ||
.prefetch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separately, I'm looking into improving the performance of parJoin
and getting rid of this prefetch
altogether, but if we're not OK with a slight performance hit we can hold this PR
|
||
fixture.test("server shutdown waits for outstanding responses to complete") { | ||
case (server, client) => | ||
IO.sleep(3.seconds) >> client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason the server isn't immediately connect-able to after the resource is acquired. I wonder if there's some detail in the NIO API about this, but I have to wait 3 seconds or else I get a Connection refused
, which seems to imply that the server socket channel hasn't even been opened yet?
|
||
import scala.concurrent.duration._ | ||
|
||
class EmberServerSuite extends Http4sSuite { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll notice that I didn't actually include any tests for the graceful shutdown mechanism... Unsurprisingly that behavior is rather hard to exercise since there's a lot of nondeterministic elements to it. In particular, we can't deterministically start a request after the server socket channel has been closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could batter it with requests and assert that every request either completed successfully or was refused a connection. But our CI is suffering enough as it is.
I got this feedback recently could this be integrated, @djspiewak believe this will also speed up so may cancel out the prefetch costs.
to
|
Does that have the semantics we want? It seems like it's going to start the handler for every socket in a separate fiber, lift that resource into stream, then immediately exit which cancels the fiber (since it introduced a scope). I think Also I realized that the |
Removed the comment I added about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this seems good.
Closes #3067. The goal of this PR is to give ember-server a graceful shutdown sequence, which @rossabaker captures succinctly in the original issue. I'd still like to add tests and follow up with some fs2 questions, but I think it's ready for review.