Fix unsafe access to perf standby status from systemview (#17186)
Ensure that we don't try to access Core.perfStandby or Core.PerfStandby() from dynamicSystemView, which might be accessed with or without stateLock held.
This commit is contained in:
parent
3aa2fe8d8f
commit
d5e0353696
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
core: fix race when using SystemView.ReplicationState outside of a request context
|
||||
```
|
|
@ -23,8 +23,9 @@ func (c ctxKeyForwardedRequestMountAccessor) String() string {
|
|||
}
|
||||
|
||||
type dynamicSystemView struct {
|
||||
core *Core
|
||||
mountEntry *MountEntry
|
||||
core *Core
|
||||
mountEntry *MountEntry
|
||||
perfStandby bool
|
||||
}
|
||||
|
||||
type extendedSystemView interface {
|
||||
|
@ -178,7 +179,7 @@ func (d dynamicSystemView) LocalMount() bool {
|
|||
// in read mode.
|
||||
func (d dynamicSystemView) ReplicationState() consts.ReplicationState {
|
||||
state := d.core.ReplicationState()
|
||||
if d.core.perfStandby {
|
||||
if d.perfStandby {
|
||||
state |= consts.ReplicationPerformanceStandby
|
||||
}
|
||||
return state
|
||||
|
|
|
@ -49,8 +49,9 @@ func verifyNamespace(*Core, *namespace.Namespace, *MountEntry) error { return ni
|
|||
func (c *Core) mountEntrySysView(entry *MountEntry) extendedSystemView {
|
||||
return extendedSystemViewImpl{
|
||||
dynamicSystemView{
|
||||
core: c,
|
||||
mountEntry: entry,
|
||||
core: c,
|
||||
mountEntry: entry,
|
||||
perfStandby: c.perfStandby,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -251,7 +251,7 @@ func NewPolicyStore(ctx context.Context, core *Core, baseView *BarrierView, syst
|
|||
func (c *Core) setupPolicyStore(ctx context.Context) error {
|
||||
// Create the policy store
|
||||
var err error
|
||||
sysView := &dynamicSystemView{core: c}
|
||||
sysView := &dynamicSystemView{core: c, perfStandby: c.perfStandby}
|
||||
psLogger := c.baseLogger.Named("policy")
|
||||
c.AddLogger(psLogger)
|
||||
c.policyStore, err = NewPolicyStore(ctx, c, c.systemBarrierView, sysView, psLogger)
|
||||
|
|
|
@ -508,7 +508,7 @@ func TestDynamicSystemView(c *Core, ns *namespace.Namespace) *dynamicSystemView
|
|||
me.namespace = ns
|
||||
}
|
||||
|
||||
return &dynamicSystemView{c, me}
|
||||
return &dynamicSystemView{c, me, c.perfStandby}
|
||||
}
|
||||
|
||||
// TestAddTestPlugin registers the testFunc as part of the plugin command to the
|
||||
|
|
Loading…
Reference in New Issue