Skip to content

Commit

Permalink
address doug's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
purnesh42H committed Dec 12, 2024
1 parent 2ed94db commit 07ec527
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions content/en/docs/guides/server-graceful-stop.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Gracefully stopping a server
title: Gracefull Shutdown
description: >-
Explains how to gracefully stop/shutdown a gRPC server.
---
Expand All @@ -17,14 +17,17 @@ accepting new RPCs. In-flight RPCs are allowed to continue until they complete
or a specified deadline is reached. Once all active RPCs finish or the deadline
expires, the server shuts down completely.

While a graceful shutdown is optional, it's highly recommended. You can
shutdown without a graceful shutdown first but that would not be recommended.

### How to do Graceful Server Shutdown

The exact implementation of the "Graceful shutdown function" varies depending on
the programming language you are using. However, the general pattern
involves:

- Initiating the graceful shutdown process by calling "Graceful shutdown
Function" on your gRPC server object. This function blocks until all
function" on your gRPC server object. This function blocks until all
currently running RPCs complete. This ensures that in-flight requests are
allowed to finish processing.
- Specify a timeout period to limit the time allowed for in-progress RPCs to
Expand All @@ -43,39 +46,29 @@ shutdown.
sequenceDiagram
Client->>Server: New RPC Request 1
Client->>Server: New RPC Request 2
Server->>Client: Processing RPC 1
Server->>Client: Processing RPC 2
Server-->>Server: Graceful Stop Invoked
Server-->>Server: Graceful Shutdown Invoked
Server->>Client: Continues Processing In-Flight RPCs
Client->>Server: New RPC Request 3 (Rejected)
Client->>Client: Detects server shutdown and go find other servers if available
alt RPCs complete within timeout
Server->>Client: Completes RPC 1
Server->>Client: Completes RPC 2
Server-->>Server: Shutdown Complete
Client->>Server: New RPC Request 4 (Rejected)
Server-->>Server: Graceful Shutdown Complete
else Timeout reached
Server->>Client: RPC 2 and other pending RPCs forcefully terminated
Server-->>Server: Shutdown Complete
Client->>Server: New RPC Request 4 (Rejected)
Server->>Client: Forceful Shutdown Invoked, terminating pending RPCs
Server-->>Server: Forceful Shutdown Complete
end
```
The following is a state based view
```mermaid
stateDiagram-v2
[*] --> RUNNING : Server Started
RUNNING --> GRACEFUL_STOP_INITIATED : GracefulStop() Called (with Timeout)
RUNNING --> GRACEFUL_STOP_INITIATED : Graceful Stop Called (with Timeout)
GRACEFUL_STOP_INITIATED --> GRACEFUL_STOPPING : Reject New RPCs
GRACEFUL_STOPPING --> TERMINATED : Complete In-Flight RPCs (Before Timeout)
GRACEFUL_STOPPING --> FORCE_STOP : Timeout Reached
FORCE_STOP --> TERMINATED : Force Terminate Pending RPCs and Shutdown
```

### Alternatives

- Forceful Shutdown: Immediately terminates the server using "Forceful Shutdown
Function" on server object, potentially interrupting active RPCs and leading
to errors on the client-side. Use only as a last resort.

### Language Support

| Language | Example |
Expand Down

0 comments on commit 07ec527

Please sign in to comment.