Skip to content

Commit

Permalink
SBT and SIGINT Signal Using CTL+C (#3250)
Browse files Browse the repository at this point in the history
* graceful shutdown and sbt.

* title

---------

Co-authored-by: Nabil Abdel-Hafeez <[email protected]>
  • Loading branch information
khajavi and 987Nabil authored Dec 16, 2024
1 parent 0fbf21b commit b643b2f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/reference/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Server.serve(routes).provide(
)
```

:::note
:::note[Handling Interrupt Signals (Ctrl+C) in SBT]
Sometimes we may want to have more control over installation of the http application into the server. In such cases, we may want to use the `Server.install` method. This method only installs the `Routes` into the server, and the lifecycle of the server can be managed separately.
:::

Expand Down Expand Up @@ -566,6 +566,12 @@ printSource("zio-http-example/src/main/scala/example/GracefulShutdown.scala")

This approach ensures that clients receive appropriate responses for their requests, rather than encountering errors or abrupt disconnections. It helps maintain the integrity of the communication between clients and the server, providing a smoother experience for users and preventing potential data loss or corruption.

:::Note
When running a server through SBT, pressing Ctrl+C doesn't cleanly shut down the application. Instead, SBT intercepts the signal and throws a `java.lang.InterruptedException`, bypassing any custom shutdown handlers you may have implemented.

However, if you run the same server directly from a packaged JAR file using `java -jar`, Ctrl+C will trigger the expected graceful shutdown sequence, allowing your application to clean up resources properly before terminating.
:::

## Idle Timeout Configuration

The idle timeout is a mechanism by which the server automatically terminates an inactive connection after a certain period of inactivity. When a client connects to the server, it establishes a connection to request and receive responses. However, there may be instances where the client becomes slow, inactive, or unresponsive, and the server needs to reclaim resources associated with idle connections to optimize server performance and resource utilization.
Expand Down

0 comments on commit b643b2f

Please sign in to comment.