Skip to content

Graceful shutdown but was still able to send request while shutting down #4332

@khanakia

Description

@khanakia

I’m using the example from here: https://gin-gonic.com/en/docs/examples/graceful-restart-or-stop/

When I send a shutdown signal and then make a GET request to Gin, the server still processes new requests even while it’s shutting down.

How can I tell Gin to stop accepting new requests as soon as shutdown starts? Otherwise, if requests are still accepted during shutdown, they might get cut off partway or even cause partial data corruption if the context deadline is reached before the request finishes.

Isn’t the point of graceful shutdown to avoid these issues?

➜  saas git:(main) ✗ go run ./cmd/shutdown
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:	export GIN_MODE=release
 - using code:	gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /slow                     --> main.gintest.func1 (3 handlers)
^C2025/08/13 11:10:14 Shutdown Server ...
[GIN] 2025/08/13 - 11:10:17 | 200 |  5.000617833s |             ::1 | GET      "/slow"
[GIN] 2025/08/13 - 11:10:22 | 200 |  5.001246625s |             ::1 | GET      "/slow"
2025/08/13 11:10:22 Server exiting

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions