-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
o/ifacestate{,apparmorprompting}: do not hold state lock during prompting startup #14413
o/ifacestate{,apparmorprompting}: do not hold state lock during prompting startup #14413
Conversation
overlord/ifacestate/ifacemgr.go
Outdated
@@ -273,6 +279,9 @@ func (m *InterfaceManager) Ensure() error { | |||
// if running. | |||
func (m *InterfaceManager) Stop() { | |||
m.stopUDevMon() | |||
// XXX: The state lock is *not* held during Stop(). If it were, we'd need | |||
// to unlock state and re-lock it after the call to | |||
// interfacesRequestsManagerStop, so that it can record notices if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedronis please confirm that this is the case, from what I could tell this is true but not certain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, afaik we don't hold the state lock when entering any of the manager methods driven by StateEngine, you could probably replace the XXX with a comment about that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to also do this in the tests:
diff --git a/overlord/ifacestate/ifacestate_test.go b/overlord/ifacestate/ifacestate_test.go
index 6836cec88e..aa808bc362 100644
--- a/overlord/ifacestate/ifacestate_test.go
+++ b/overlord/ifacestate/ifacestate_test.go
@@ -378,12 +378,16 @@ func (s *interfaceManagerSuite) TestSmokeAppArmorPromptingEnabled(c *C) {
fakeManager := &apparmorprompting.InterfacesRequestsManager{}
restore = ifacestate.MockCreateInterfacesRequestsManager(func(s *state.State) (*apparmorprompting.InterfacesRequestsManager, error) {
createCount++
+ s.Lock()
+ s.Unlock()
return fakeManager, nil
})
defer restore()
stopCount := 0
restore = ifacestate.MockInterfacesRequestsManagerStop(func(m *apparmorprompting.InterfacesRequestsManager) error {
stopCount++
+ s.st.Lock()
+ s.st.Unlock()
return nil
})
defer restore()
Maybe there are other or better tests to do that in?
Also as suggested elsewhere we should have stop - start test for snapd with the apparmor prompting feature kept enabled
overlord/ifacestate/ifacemgr.go
Outdated
@@ -273,6 +279,9 @@ func (m *InterfaceManager) Ensure() error { | |||
// if running. | |||
func (m *InterfaceManager) Stop() { | |||
m.stopUDevMon() | |||
// XXX: The state lock is *not* held during Stop(). If it were, we'd need | |||
// to unlock state and re-lock it after the call to | |||
// interfacesRequestsManagerStop, so that it can record notices if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, afaik we don't hold the state lock when entering any of the manager methods driven by StateEngine, you could probably replace the XXX with a comment about that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you
8e79c7c
to
fb26ec0
Compare
Had a typo :( |
Client integration tests are passing again with this PR. Tested by rebasing #14387 on this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
I don't believe recording notices in goroutines is actually incorrect, it I think it just may be confusing to the test runtime. Some investigation here: canonical/prompting-client#81 Regardless, I think it's clearer for the client if all notices occur in order and before API calls return, so this PR is still worth merging. In the future, we can explore ways to record notices synchronously without requiring the state lock. |
5b5be0b
to
3247a63
Compare
…ts manager Signed-off-by: Oliver Calder <oliver.calder@canonical.com> o/ifacestate: test state lock during interfaces requests manager startup Signed-off-by: Oliver Calder <oliver.calder@canonical.com> tests: add test of snapd startup with apparmor prompting enabled Signed-off-by: Oliver Calder <oliver.calder@canonical.com> tests: check that snapd successfully shuts down and restarts with prompting enabled Signed-off-by: Oliver Calder <oliver.calder@canonical.com> tests: fix formatting of after arg in prompting notices query Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
3247a63
to
17fcbca
Compare
I rebased to clean up the history and preserve the |
Recording notices requires state lock, but recording notices asynchronously can cause unexpected behavior for the client. Thus, explicitly unlock state if the state lock is held when we know notices may be recorded; namely, during ifacemgr
StartUp
.This reverts #14405. This is tracked internally by https://warthogs.atlassian.net/browse/SNAPDENG-31228