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

Stopping server, upgrading prod. server, auto-reload #52

Open
webleaf opened this issue Mar 15, 2024 · 1 comment
Open

Stopping server, upgrading prod. server, auto-reload #52

webleaf opened this issue Mar 15, 2024 · 1 comment

Comments

@webleaf
Copy link

webleaf commented Mar 15, 2024

I have a few questions:

  1. Stopping server. I expect ability to correctly stop server. I mean, after server get stop signal, it should stop accepting and processing new requests (responding to them with 503), but shut down only after processing the ones already accepted. How does this work in klite?
  2. How properly upgrade server in production?
  3. How to automatically restart the server if it crashes in production? Watchdog?
  4. Jooby and Ktor have hot-reload/auto-reload feature in development mode. How development workflow looks with klite?
@angryziber
Copy link
Member

  1. If you look at implementation of Server.start() method - it registers a JVM shutdown hook to do a graceful shutdown, which is actually implemented by jdk.httpserver itself - it closes the port, so that proxies/load balancers know that it doesn't accept any more requests, but finishes the currently running ones for up to 3 seconds (you can specify your value as a parameter). There are no 503 responses, as these may be propagated to the end-user.

  2. Docker/Heroku/Google Cloud Run/Fly.io - all do this correctly. In general, they will start a new container, wait for it to open http port and then redirect traffic there. This should work the same no matter which framework do you use.

  3. Docker and all of the the above would do it automatically for you.

  4. Klite doesn't have any magic built it, but it restarts in less than 1 second, so you just change your code/run tests and then restart the server when ready. JVM hot reload works for changed code inside of functions, but not signatures, like usual. Usually classloader auto-reload hacks are needed if your server starts slowly.

In general, Klite is built with 12-factor apps principles in mind regarding deployment.

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

No branches or pull requests

2 participants