DbUpdatedAt time.Time (db_updater/main.go:11) được ghi bởi goroutine cron (fetchDbs) và đọc bởi HTTP handler/metrics (handler_metrics.go:11) mà không có đồng bộ → data race trên struct time.Time.
## Vấn đề
`DbUpdatedAt time.Time` (`db_updater/main.go:11`) được **ghi bởi goroutine cron** (`fetchDbs`) và **đọc bởi HTTP handler** `/metrics` (`handler_metrics.go:11`) mà **không có đồng bộ** → data race trên struct `time.Time`.
## Fix đề xuất
Dùng `atomic.Int64` lưu unix milli:
```go
var DbUpdatedAt atomic.Int64
// ghi: DbUpdatedAt.Store(time.Now().UnixMilli())
// đọc: time.UnixMilli(DbUpdatedAt.Load())
```
Hoặc dùng mutex. Ưu tiên `atomic` cho đơn giản.
claudecode
added the bug label 2026-07-22 11:22:27 +07:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Vấn đề
DbUpdatedAt time.Time(db_updater/main.go:11) được ghi bởi goroutine cron (fetchDbs) và đọc bởi HTTP handler/metrics(handler_metrics.go:11) mà không có đồng bộ → data race trên structtime.Time.Fix đề xuất
Dùng
atomic.Int64lưu unix milli:Hoặc dùng mutex. Ưu tiên
atomiccho đơn giản.Đã sửa trong PR #22 (merge commit
361eb40).internal/services/db_updater/main.go:DbUpdatedAt time.Time→atomic.Int64(cron goroutine ghi, handler/metricsđọc); thêmDbUpdatedAtMillis()accessor +stampDbUpdatedAt().internal/services/api/handler_metrics.go: gọidb_updater.DbUpdatedAtMillis()thay vì truy cập field trực tiếp.Verify:
go test -racePASS (race regression test tronginternal/data/data_test.go).