feat(engine): add Shutdown method for graceful shutdown#4501
feat(engine): add Shutdown method for graceful shutdown#4501Narita-1095305 wants to merge 1 commit intogin-gonic:masterfrom
Conversation
74a355d to
c595cae
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4501 +/- ##
==========================================
- Coverage 99.21% 99.01% -0.21%
==========================================
Files 42 45 +3
Lines 3182 3035 -147
==========================================
- Hits 3157 3005 -152
- Misses 17 21 +4
- Partials 8 9 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
67d083f to
f61c6d0
Compare
- Add server and serverLock fields to Engine struct - Add Shutdown() method that calls http.Server.Shutdown() - Modify Run/RunTLS/RunUnix/RunListener to store server reference - Add RunWithShutdown convenience method with signal handling - Add comprehensive tests for graceful shutdown (8 test cases) - Fix lint errors (errorlint, testifylint, errcheck)
f61c6d0 to
f894f4c
Compare
Note on Codecov Project CoverageThe Verification
Cause of Coverage DropThe slight decrease is not caused by the code in this PR. Local testing confirms: The project-wide coverage drop is related to existing packages (e.g., I believe this PR should be acceptable for review since all modified and added code has 100% test coverage. |
Add Engine.Shutdown() method for graceful shutdown support
Description
This PR adds built-in graceful shutdown support to Gin Engine, allowing users to properly wait for active connections to finish before shutting down the server.
Changes
serverandserverLockfields to Engine struct to store server referenceShutdown(ctx context.Context)method that callshttp.Server.Shutdown()Run(),RunTLS(),RunUnix(),RunListener()to store server referenceRunWithShutdown()convenience method with built-in signal handlingUsage
Or use the convenience method:
Related Issue
Addresses the need for built-in graceful shutdown support mentioned in documentation.
Checklist