fix: API 서버 코드 리뷰 버그 15건 수정 (CRITICAL 2, HIGH 2, MEDIUM 11)
All checks were successful
Server CI/CD / lint-and-build (push) Successful in 38s
Server CI/CD / deploy (push) Successful in 50s

CRITICAL:
- graceful shutdown 레이스 수정 — Listen을 goroutine으로 이동
- Register 레이스 컨디션 — sentinel error + MySQL duplicate key 처리

HIGH:
- 멱등성 키에 method+path 포함 — 엔드포인트 간 캐시 충돌 방지
- 입장 토큰 생성 실패 시 방/슬롯 롤백 추가

MEDIUM:
- RequestEntry 슬롯 없음 시 503 반환
- chain ExportWallet/GetWalletInfo/GrantReward 에러 처리 개선
- resolveUsername 에러 타입 구분 (duplicate key vs 기타)
- 공지사항 길이 검증 byte→rune (한국어 256자 허용)
- Level 검증 범위 MaxLevel(50)로 통일
- admin 자기 강등 방지
- CORS ExposeHeaders 추가
- MySQL DSN loc=Local→loc=UTC
- hashGameExeFromZip 100MB 초과 절단 감지

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 18:05:27 +09:00
parent c9af89a852
commit b006fe77c2
14 changed files with 112 additions and 47 deletions

View File

@@ -1,6 +1,12 @@
package apperror
import "fmt"
import (
"errors"
"fmt"
"strings"
"github.com/go-sql-driver/mysql"
)
// AppError is a structured application error with an HTTP status code.
// JSON response format: {"error": "<code>", "message": "<human-readable message>"}
@@ -57,3 +63,15 @@ func Conflict(message string) *AppError {
func Internal(message string) *AppError {
return &AppError{Code: "internal_error", Message: message, Status: 500}
}
// ErrDuplicateUsername is returned when a username already exists.
var ErrDuplicateUsername = fmt.Errorf("이미 사용 중인 아이디입니다")
// IsDuplicateEntry checks if a GORM error is a MySQL duplicate key violation (error 1062).
func IsDuplicateEntry(err error) bool {
var mysqlErr *mysql.MySQLError
if errors.As(err, &mysqlErr) {
return mysqlErr.Number == 1062
}
return strings.Contains(err.Error(), "Duplicate entry") || strings.Contains(err.Error(), "UNIQUE constraint")
}

View File

@@ -11,7 +11,7 @@ import (
func ConnectMySQL() (*gorm.DB, error) {
c := config.C
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=UTC",
c.DBUser, c.DBPassword, c.DBHost, c.DBPort, c.DBName,
)
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})

View File

@@ -49,7 +49,7 @@ func Idempotency(rdb *redis.Client) fiber.Handler {
if uid, ok := c.Locals("userID").(uint); ok {
redisKey += fmt.Sprintf("u%d:", uid)
}
redisKey += key
redisKey += c.Method() + ":" + c.Route().Path + ":" + key
ctx, cancel := context.WithTimeout(context.Background(), redisTimeout)
defer cancel()