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 {
|
type dynamicSystemView struct {
|
||||||
core *Core
|
core *Core
|
||||||
mountEntry *MountEntry
|
mountEntry *MountEntry
|
||||||
|
perfStandby bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type extendedSystemView interface {
|
type extendedSystemView interface {
|
||||||
|
@ -178,7 +179,7 @@ func (d dynamicSystemView) LocalMount() bool {
|
||||||
// in read mode.
|
// in read mode.
|
||||||
func (d dynamicSystemView) ReplicationState() consts.ReplicationState {
|
func (d dynamicSystemView) ReplicationState() consts.ReplicationState {
|
||||||
state := d.core.ReplicationState()
|
state := d.core.ReplicationState()
|
||||||
if d.core.perfStandby {
|
if d.perfStandby {
|
||||||
state |= consts.ReplicationPerformanceStandby
|
state |= consts.ReplicationPerformanceStandby
|
||||||
}
|
}
|
||||||
return state
|
return state
|
||||||
|
|
|
@ -49,8 +49,9 @@ func verifyNamespace(*Core, *namespace.Namespace, *MountEntry) error { return ni
|
||||||
func (c *Core) mountEntrySysView(entry *MountEntry) extendedSystemView {
|
func (c *Core) mountEntrySysView(entry *MountEntry) extendedSystemView {
|
||||||
return extendedSystemViewImpl{
|
return extendedSystemViewImpl{
|
||||||
dynamicSystemView{
|
dynamicSystemView{
|
||||||
core: c,
|
core: c,
|
||||||
mountEntry: entry,
|
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 {
|
func (c *Core) setupPolicyStore(ctx context.Context) error {
|
||||||
// Create the policy store
|
// Create the policy store
|
||||||
var err error
|
var err error
|
||||||
sysView := &dynamicSystemView{core: c}
|
sysView := &dynamicSystemView{core: c, perfStandby: c.perfStandby}
|
||||||
psLogger := c.baseLogger.Named("policy")
|
psLogger := c.baseLogger.Named("policy")
|
||||||
c.AddLogger(psLogger)
|
c.AddLogger(psLogger)
|
||||||
c.policyStore, err = NewPolicyStore(ctx, c, c.systemBarrierView, sysView, 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
|
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
|
// TestAddTestPlugin registers the testFunc as part of the plugin command to the
|
||||||
|
|
Loading…
Reference in New Issue