fix: add deadline to jwk register
All checks were successful
Docker Build and Push / build-and-push-tags (push) Has been skipped
renovate / renovate (push) Successful in 44s
Docker Build and Push / build-and-push-branches (push) Successful in 4m0s

This commit is contained in:
2026-01-04 17:10:28 +07:00
parent a98682d42f
commit 6124df8911
2 changed files with 10 additions and 7 deletions

10
main.go
View File

@@ -20,7 +20,7 @@ import (
func main() {
if _, err := os.Stat(".env"); err == nil {
if err := godotenv.Load(".env"); err != nil {
if err = godotenv.Load(".env"); err != nil {
log.Printf("Warning: Failed to load .env file: %s", err)
}
}
@@ -50,7 +50,7 @@ func main() {
return
}
defer func(connect *pgx.Conn, ctx context.Context) {
err := connect.Close(ctx)
err = connect.Close(ctx)
if err != nil {
panic(err)
}
@@ -70,13 +70,13 @@ func main() {
errCh := make(chan error, 2)
go func() {
if err := s.StartAPI(ctx, apiAddr); err != nil && !errors.Is(err, context.Canceled) {
if err = s.StartAPI(ctx, apiAddr); err != nil && !errors.Is(err, context.Canceled) {
errCh <- err
}
}()
go func() {
if err := s.StartController(ctx, controllerAddr); err != nil && !errors.Is(err, context.Canceled) {
if err = s.StartController(ctx, controllerAddr); err != nil && !errors.Is(err, context.Canceled) {
errCh <- err
}
}()
@@ -84,7 +84,7 @@ func main() {
select {
case <-ctx.Done():
log.Printf("shutting down: %v", ctx.Err())
case err := <-errCh:
case err = <-errCh:
log.Fatalf("server error: %v", err)
}
}

View File

@@ -28,6 +28,7 @@ import (
const (
defaultSubscriberResponseWait = 5 * time.Second
jwkRegisterTimeout = 5 * time.Second
)
type Subscriber struct {
@@ -352,10 +353,12 @@ func (s *Server) StartAPI(ctx context.Context, Addr string) error {
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
}
jwkURL := config.Getenv("JWKS_URL", "")
if jwkURL != "" {
if err := s.jwkCache.Register(ctx, jwkURL); err != nil {
registerCtx, cancel := context.WithTimeout(ctx, jwkRegisterTimeout)
defer cancel()
if err := s.jwkCache.Register(registerCtx, jwkURL); err != nil {
return fmt.Errorf("failed to register jwk cache: %w", err)
}
}