Skip to content

Commit ab8dd24

Browse files
committed
fix: add GUARDED_BY annotations to readiness Gate fields
Add required mutex guard annotations for the lint analyzer. Replace interface{} with any (Go 1.18+ style).
1 parent 670e7af commit ab8dd24

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

pkg/middleware/readiness/readiness.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ type Gate struct {
4747
sfGroup singleflight.Group
4848

4949
mu sync.RWMutex
50-
cachedReady bool
51-
cachedMessage string
52-
cacheTime time.Time
50+
cachedReady bool // GUARDED_BY(mu)
51+
cachedMessage string // GUARDED_BY(mu)
52+
cacheTime time.Time // GUARDED_BY(mu)
5353
}
5454

5555
// NewGate creates a new readiness gate with the given checker.
@@ -87,7 +87,7 @@ func (g *Gate) isReady(ctx context.Context) (bool, string) {
8787
g.mu.RUnlock()
8888

8989
// Slow path: use singleflight to deduplicate concurrent checks
90-
result, _, _ := g.sfGroup.Do("readiness", func() (interface{}, error) {
90+
result, _, _ := g.sfGroup.Do("readiness", func() (any, error) {
9191
// Double-check cache after acquiring singleflight
9292
g.mu.RLock()
9393
elapsed := time.Since(g.cacheTime)
@@ -149,7 +149,7 @@ func formatNotReadyError(msg string) error {
149149
// UnaryServerInterceptor returns a gRPC unary interceptor that blocks
150150
// requests until the datastore is ready.
151151
func (g *Gate) UnaryServerInterceptor() grpc.UnaryServerInterceptor {
152-
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
152+
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
153153
// Bypass health checks so Kubernetes probes work
154154
if strings.HasPrefix(info.FullMethod, healthCheckPrefix) {
155155
return handler(ctx, req)
@@ -167,7 +167,7 @@ func (g *Gate) UnaryServerInterceptor() grpc.UnaryServerInterceptor {
167167
// StreamServerInterceptor returns a gRPC stream interceptor that blocks
168168
// streams until the datastore is ready.
169169
func (g *Gate) StreamServerInterceptor() grpc.StreamServerInterceptor {
170-
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
170+
return func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
171171
// Bypass health checks so Kubernetes probes work
172172
if strings.HasPrefix(info.FullMethod, healthCheckPrefix) {
173173
return handler(srv, ss)

pkg/middleware/readiness/readiness_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestGate_BlocksWhenNotReady(t *testing.T) {
4444
interceptor := gate.UnaryServerInterceptor()
4545
_, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
4646
FullMethod: "/authzed.api.v1.PermissionsService/CheckPermission",
47-
}, func(ctx context.Context, req interface{}) (interface{}, error) {
47+
}, func(ctx context.Context, req any) (any, error) {
4848
t.Fatal("handler should not be called when not ready")
4949
return nil, nil
5050
})
@@ -65,7 +65,7 @@ func TestGate_AllowsWhenReady(t *testing.T) {
6565
interceptor := gate.UnaryServerInterceptor()
6666
_, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
6767
FullMethod: "/authzed.api.v1.PermissionsService/CheckPermission",
68-
}, func(ctx context.Context, req interface{}) (interface{}, error) {
68+
}, func(ctx context.Context, req any) (any, error) {
6969
handlerCalled = true
7070
return "response", nil
7171
})
@@ -85,7 +85,7 @@ func TestGate_BypassesHealthCheck(t *testing.T) {
8585
interceptor := gate.UnaryServerInterceptor()
8686
_, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
8787
FullMethod: "/grpc.health.v1.Health/Check",
88-
}, func(ctx context.Context, req interface{}) (interface{}, error) {
88+
}, func(ctx context.Context, req any) (any, error) {
8989
handlerCalled = true
9090
return "ok", nil
9191
})
@@ -107,7 +107,7 @@ func TestGate_BypassesHealthWatch(t *testing.T) {
107107
interceptor := gate.UnaryServerInterceptor()
108108
_, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
109109
FullMethod: "/grpc.health.v1.Health/Watch",
110-
}, func(ctx context.Context, req interface{}) (interface{}, error) {
110+
}, func(ctx context.Context, req any) (any, error) {
111111
handlerCalled = true
112112
return "ok", nil
113113
})
@@ -122,7 +122,7 @@ func TestGate_CachesReadyState(t *testing.T) {
122122

123123
interceptor := gate.UnaryServerInterceptor()
124124
info := &grpc.UnaryServerInfo{FullMethod: "/test/Method"}
125-
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
125+
handler := func(ctx context.Context, req any) (any, error) {
126126
return nil, nil
127127
}
128128

@@ -152,7 +152,7 @@ func TestGate_CacheExpires(t *testing.T) {
152152
interceptor := gate.UnaryServerInterceptor()
153153
_, _ = interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
154154
FullMethod: "/test/Method",
155-
}, func(ctx context.Context, req interface{}) (interface{}, error) {
155+
}, func(ctx context.Context, req any) (any, error) {
156156
return nil, nil
157157
})
158158

@@ -167,7 +167,7 @@ func TestGate_SingleflightPreventsThunderingHerd(t *testing.T) {
167167

168168
interceptor := gate.UnaryServerInterceptor()
169169
info := &grpc.UnaryServerInfo{FullMethod: "/test/Method"}
170-
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
170+
handler := func(ctx context.Context, req any) (any, error) {
171171
return nil, nil
172172
}
173173

@@ -196,7 +196,7 @@ func TestGate_HandlesCheckerError(t *testing.T) {
196196
interceptor := gate.UnaryServerInterceptor()
197197
_, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
198198
FullMethod: "/test/Method",
199-
}, func(ctx context.Context, req interface{}) (interface{}, error) {
199+
}, func(ctx context.Context, req any) (any, error) {
200200
t.Fatal("handler should not be called on error")
201201
return nil, nil
202202
})
@@ -218,7 +218,7 @@ func TestGate_StreamInterceptorBlocksWhenNotReady(t *testing.T) {
218218
interceptor := gate.StreamServerInterceptor()
219219
err := interceptor(nil, &mockServerStream{}, &grpc.StreamServerInfo{
220220
FullMethod: "/authzed.api.v1.WatchService/Watch",
221-
}, func(srv interface{}, stream grpc.ServerStream) error {
221+
}, func(srv any, stream grpc.ServerStream) error {
222222
t.Fatal("handler should not be called when not ready")
223223
return nil
224224
})
@@ -237,7 +237,7 @@ func TestGate_StreamInterceptorAllowsWhenReady(t *testing.T) {
237237
interceptor := gate.StreamServerInterceptor()
238238
err := interceptor(nil, &mockServerStream{}, &grpc.StreamServerInfo{
239239
FullMethod: "/authzed.api.v1.WatchService/Watch",
240-
}, func(srv interface{}, stream grpc.ServerStream) error {
240+
}, func(srv any, stream grpc.ServerStream) error {
241241
handlerCalled = true
242242
return nil
243243
})
@@ -266,7 +266,7 @@ func TestGate_NilCheckerPassesThrough(t *testing.T) {
266266
interceptor := gate.UnaryServerInterceptor()
267267
_, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
268268
FullMethod: "/authzed.api.v1.PermissionsService/CheckPermission",
269-
}, func(ctx context.Context, req interface{}) (interface{}, error) {
269+
}, func(ctx context.Context, req any) (any, error) {
270270
handlerCalled = true
271271
return "response", nil
272272
})
@@ -281,7 +281,7 @@ func TestGate_ErrorDoesNotCache(t *testing.T) {
281281

282282
interceptor := gate.UnaryServerInterceptor()
283283
info := &grpc.UnaryServerInfo{FullMethod: "/test/Method"}
284-
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
284+
handler := func(ctx context.Context, req any) (any, error) {
285285
return nil, nil
286286
}
287287

@@ -296,7 +296,7 @@ func TestGate_ErrorDoesNotCache(t *testing.T) {
296296

297297
// Second call should retry (not use cached error)
298298
handlerCalled := false
299-
_, err = interceptor(context.Background(), nil, info, func(ctx context.Context, req interface{}) (interface{}, error) {
299+
_, err = interceptor(context.Background(), nil, info, func(ctx context.Context, req any) (any, error) {
300300
handlerCalled = true
301301
return "ok", nil
302302
})
@@ -314,7 +314,7 @@ func TestGate_NegativeCacheReducesChecks(t *testing.T) {
314314

315315
interceptor := gate.UnaryServerInterceptor()
316316
info := &grpc.UnaryServerInfo{FullMethod: "/test/Method"}
317-
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
317+
handler := func(ctx context.Context, req any) (any, error) {
318318
return nil, nil
319319
}
320320

@@ -365,7 +365,7 @@ func TestGate_ErrorMessageContextAware(t *testing.T) {
365365
interceptor := gate.UnaryServerInterceptor()
366366
_, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
367367
FullMethod: "/test/Method",
368-
}, func(ctx context.Context, req interface{}) (interface{}, error) {
368+
}, func(ctx context.Context, req any) (any, error) {
369369
return nil, nil
370370
})
371371

0 commit comments

Comments
 (0)