Feature Request: Implement Graceful Shutdown for Garnet
- Dominant language
- C#
- Stars
- 12k
- Forks
- 703
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 36
Description
### Feature request type
enhancement
### Is your feature request related to a problem? Please describe
When Garnet is run as a Windows Service using `Garnet.Worker.exe`, it shuts down immediately upon receiving a stop signal from the Service Control Manager (e.g., via `services.msc` or `sc stop`).
This behavior can lead to data loss for any in-memory data that has not yet been persisted to disk through the AOF or a recent checkpoint. A graceful shutdown mechanism is needed to ensure data integrity.
### Describe the solution you'd like
The `Garnet.Worker` service host should properly handle the `OnStop` event from the Windows Service base class. The desired workflow is as follows:
1. The `Garnet.Worker` service intercepts the stop signal from Windows.
2. Before terminating the process, the service issues a `SAVE` command to the Garnet server to ensure all data is flushed to disk.
3. The service should wait for the save operation to complete successfully before allowing the process to exit.
### Describe alternatives you've considered
The current alternative is to manually connect to the Garnet instance with a client (e.g., `redis-cli`) and issue a `SAVE` command before stopping the service. This is not ideal for automated environments and is prone to human error.
### Additional context
For context, here is how the Garnet Windows Service is being created:
```cmd
set SVCEXE="C:\garnet\Service\Garnet.Worker.exe"
sc create Garnet binPath= "%SVCEXE% --config-import-path \"C:\Garnet\garnet.conf\"" start= auto
sc description Garnet "Garnet (RESP) with storage+AOF+compaction"
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the Garnet.Worker Windows Service host and its OnStop handling. Trace how the service can issue the SAVE command and wait for completion before process exit, then verify behavior when stopping through the Service Control Manager, including that the save completes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100