Skip to content

Commit 14f581a

Browse files
erikhortschclaude
andauthored
rpc: gate the claim skip process-wide for every server (#1729)
* rpc: gate the claim skip process-wide for every server Wires psrpc's WithServerSkipClaim into WithServerObservability, which is the one seam every server constructor shares -- WithDefaultServerOptions calls it, and the constructors that take only a logger reach it too. The setting is process-wide because the claim is a transport policy rather than a per-service one, and it is read per request so callers may set it before or after their servers exist and revoke it without a redeploy. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * pin psrpc v0.7.5, trim comments Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * rename the skip-claim gate to carry the psrpc prefix Server and client mean too many things in this package for a bare SetServerSkipClaim to read clearly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 64286ea commit 14f581a

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/jxskiss/base62 v1.1.0
1717
github.com/lithammer/shortuuid/v4 v4.2.0
1818
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731
19-
github.com/livekit/psrpc v0.7.3
19+
github.com/livekit/psrpc v0.7.5
2020
github.com/mackerelio/go-osstat v0.2.8
2121
github.com/maxbrunsfeld/counterfeiter/v6 v6.12.2
2222
github.com/nyaruka/phonenumbers v1.8.1

‎go.sum‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5AT
8787
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
8888
github.com/livekit/psrpc v0.7.3 h1:bekuZt/ZQzg8+/M8G6G5jq7bvV9fAKdPHSOZeTwrIIc=
8989
github.com/livekit/psrpc v0.7.3/go.mod h1:rAI+m2+/cb4x9RXhLRtUx5ZwdfjjXOl4zi46IjEetaw=
90+
github.com/livekit/psrpc v0.7.5-0.20260819230101-cbf56a2f6872 h1:T4+LTChYiNKWkK2yeW0FXB2CNpEXxiHEV75Xhh8lDUI=
91+
github.com/livekit/psrpc v0.7.5-0.20260819230101-cbf56a2f6872/go.mod h1:rAI+m2+/cb4x9RXhLRtUx5ZwdfjjXOl4zi46IjEetaw=
92+
github.com/livekit/psrpc v0.7.5 h1:WxfJIQ41X1b+48A1uzc8Gy9FhYEMxBJNCpCYqPdO/Ds=
93+
github.com/livekit/psrpc v0.7.5/go.mod h1:rAI+m2+/cb4x9RXhLRtUx5ZwdfjjXOl4zi46IjEetaw=
9094
github.com/mackerelio/go-osstat v0.2.8 h1:I2duicTaCGWoM53XwAwA9OIe1inu0xnVs8/pqOWWVr4=
9195
github.com/mackerelio/go-osstat v0.2.8/go.mod h1:SyS3XxKdoSKJnTGTkN5Yrh6VUQVuAURACfE6y+2DN4k=
9296
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=

‎rpc/typed_api.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package rpc
1717
import (
1818
"context"
1919
"fmt"
20+
"sync/atomic"
2021
"time"
2122

2223
"github.com/livekit/psrpc"
@@ -97,12 +98,29 @@ func (p *ClientParams) Args() (psrpc.MessageBus, psrpc.ClientOption) {
9798
return p.Bus, psrpc.WithClientOptions(p.Options()...)
9899
}
99100

101+
var psrpcServerSkipClaim atomic.Pointer[func() bool]
102+
103+
// SetPSRPCServerSkipClaim gates the claim skip for every server built through
104+
// WithServerObservability. Process-wide; read per request, so revocable at runtime.
105+
func SetPSRPCServerSkipClaim(enabled func() bool) {
106+
psrpcServerSkipClaim.Store(&enabled)
107+
}
108+
109+
func psrpcServerSkipClaimEnabled() bool {
110+
if enabled := psrpcServerSkipClaim.Load(); enabled != nil {
111+
return (*enabled)()
112+
}
113+
return false
114+
}
115+
100116
func WithServerObservability(logger logger.Logger) psrpc.ServerOption {
101117
return psrpc.WithServerOptions(
102118
middleware.WithServerMetrics(PSRPCMetricsObserver{}),
103119
psrpc.WithServerObserver(PSRPCMetricsObserver{}),
104120
WithServerLogger(logger),
105121
otelpsrpc.ServerOptions(otelpsrpc.Config{}),
122+
// here rather than WithDefaultServerOptions so logger-only servers get it too
123+
psrpc.WithServerSkipClaim(psrpcServerSkipClaimEnabled),
106124
)
107125
}
108126

‎rpc/typed_api_test.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
reflect "reflect"
77
"runtime"
88
"slices"
9+
"sync/atomic"
910
"testing"
1011
"time"
1112

@@ -76,3 +77,19 @@ func TestPropagateRequestTimeout(t *testing.T) {
7677
WithPropagateRequestTimeout(ctx)(&ro)
7778
require.InEpsilon(t, 42*time.Second, ro.Timeout, 0.01)
7879
}
80+
81+
func TestServerSkipClaim(t *testing.T) {
82+
t.Cleanup(func() { psrpcServerSkipClaim.Store(nil) })
83+
84+
require.False(t, psrpcServerSkipClaimEnabled(), "unset must mean claim")
85+
86+
var on atomic.Bool
87+
SetPSRPCServerSkipClaim(on.Load)
88+
require.False(t, psrpcServerSkipClaimEnabled())
89+
90+
on.Store(true)
91+
require.True(t, psrpcServerSkipClaimEnabled(), "must be read per call, not captured")
92+
93+
on.Store(false)
94+
require.False(t, psrpcServerSkipClaimEnabled(), "must stay revocable")
95+
}

0 commit comments

Comments
 (0)