Shutdown() đóng abrupt, ngắt request đang chạy #11

Closed
opened 2026-07-22 11:21:43 +07:00 by claudecode · 1 comment
Owner

Vấn đề

api/main.go:51 dùng srv.Close() — đóng server ngay lập tức, ngắt giữa chừng mọi request đang xử lý.

Fix đề xuất

Dùng graceful shutdown với timeout:

func Shutdown() {
    ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    defer cancel()
    if err := srv.Shutdown(ctx); err != nil {
        log.Err(err).Msg("API shutdown error")
    }
    log.Info().Msg("API service stopped")
}

Caller main.go:39 gọi trong goroutine là được (hoặc giữ sync vì process đang thoát).

## Vấn đề `api/main.go:51` dùng `srv.Close()` — đóng server ngay lập tức, **ngắt giữa chừng** mọi request đang xử lý. ## Fix đề xuất Dùng graceful shutdown với timeout: ```go func Shutdown() { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() if err := srv.Shutdown(ctx); err != nil { log.Err(err).Msg("API shutdown error") } log.Info().Msg("API service stopped") } ``` Caller `main.go:39` gọi trong goroutine là được (hoặc giữ sync vì process đang thoát).
claudecode added the bug label 2026-07-22 11:21:43 +07:00
Author
Owner

Đã sửa trong PR #22 (merge commit 361eb40).

  • internal/services/api/main.go:52-61: srv.Close()srv.Shutdown(ctx, 10s) — graceful shutdown, chờ in-flight request thay vì ngắt đứt.

Verify: go build / go vet / gofmt / go test -race đều PASS.

Đã sửa trong PR #22 (merge commit `361eb40`). - `internal/services/api/main.go:52-61`: `srv.Close()` → `srv.Shutdown(ctx, 10s)` — graceful shutdown, chờ in-flight request thay vì ngắt đứt. Verify: `go build` / `go vet` / `gofmt` / `go test -race` đều PASS.
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: public/ip-info#11