-
Notifications
You must be signed in to change notification settings - Fork 680
o/ifacestate: properly handle undo scenarios where auto-connections are dropped #17018
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
Merged
andrewphelpsj
merged 6 commits into
canonical:master
from
andrewphelpsj:fix-connection-undo
May 11, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e07c813
o/ifacestate, tests: add tests that reproduce incorrect undo scenarios
andrewphelpsj 5a5154a
o/ifacestate: properly handle undo scenarios where auto-connections a…
andrewphelpsj 86bc62d
fixup! o/ifacestate: properly handle undo scenarios where auto-connec…
andrewphelpsj 3faf92e
fixup! o/ifacestate: properly handle undo scenarios where auto-connec…
andrewphelpsj d0bd8c6
o/ifacestate: use consistent variable name for reloaded connections s…
andrewphelpsj d56f83c
o/ifacestate: add some comments and rename some functions to hopefull…
andrewphelpsj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -337,6 +337,9 @@ func (d delayedEffectsForSnaps) EnqueueFor(snapName affectedSnap, backend interf | |
| d[snapName][backend] = append(d[snapName][backend], item) | ||
| } | ||
|
|
||
| // refreshAppSetConnections refreshes repository connections for appSet and, on | ||
| // the setup-profiles do path, records undo data for persisted connection state | ||
| // that reloadConnections changed or dropped. | ||
| func (m *InterfaceManager) refreshAppSetConnections(task *state.Task, appSet *interfaces.SnapAppSet) ([]string, []string, error) { | ||
| snapInfo := appSet.Info() | ||
| snapName := appSet.InstanceName() | ||
|
|
@@ -369,11 +372,21 @@ func (m *InterfaceManager) refreshAppSetConnections(task *state.Task, appSet *in | |
| task.Logf("%s", snap.BadInterfacesSummary(snapInfo)) | ||
| } | ||
|
|
||
| affectedConnections, err := m.reloadConnections(snapName) | ||
| reloadedConns, changedOrDroppedConns, err := m.reloadConnections(snapName) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| return disconnectedSnaps, affectedConnections, nil | ||
|
|
||
| // if this task modified any connection states, take a snapshot of the | ||
| // original connections so that setup-profiles' undo can restore them, if | ||
| // needed | ||
| if task.Status() != state.UndoingStatus { | ||
| if err := snapshotChangedConnectionsForUndo(task, snapName, changedOrDroppedConns); err != nil { | ||
| return nil, nil, err | ||
| } | ||
| } | ||
|
|
||
| return disconnectedSnaps, reloadedConns, nil | ||
| } | ||
|
|
||
| func (m *InterfaceManager) setupProfilesForAppSet( | ||
|
|
@@ -385,7 +398,7 @@ func (m *InterfaceManager) setupProfilesForAppSet( | |
| st := task.State() | ||
|
|
||
| snapName := appSet.InstanceName() | ||
| disconnectedSnaps, affectedConnections, err := m.refreshAppSetConnections(task, appSet) | ||
| disconnectedSnaps, reloadedConns, err := m.refreshAppSetConnections(task, appSet) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -399,7 +412,7 @@ func (m *InterfaceManager) setupProfilesForAppSet( | |
| snapsWithConnectedSlots := make(map[string]bool) | ||
| newConnectedSnaps := make(map[string]bool) | ||
| // Identify affected snaps on either side of the connection. | ||
| for _, connID := range affectedConnections { | ||
| for _, connID := range reloadedConns { | ||
| connRef, err := interfaces.ParseConnRef(connID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("internal error: cannot parse existing connection: %w", err) | ||
|
|
@@ -697,6 +710,13 @@ func (m *InterfaceManager) undoSetupProfiles(task *state.Task, tomb *tomb.Tomb) | |
| return err | ||
| } | ||
|
|
||
| // restore any connection state snapshot saved by refreshAppSetConnections on | ||
| // the original setup-profiles do path before rebuilding profiles for the old | ||
| // revision | ||
| if err := restoreConnectionsForSetupProfiles(task); err != nil { | ||
| return err | ||
| } | ||
|
Comment on lines
+716
to
+718
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should mention that it relies on the task variable being set by |
||
|
|
||
| // Get the name from SnapSetup and use it to find the current SideInfo | ||
| // about the snap, if there is one. | ||
| var snapst snapstate.SnapState | ||
|
|
@@ -2003,7 +2023,7 @@ func (m *InterfaceManager) transitionConnectionsCoreMigration(st *state.State, o | |
| // on disk are rewritten. This is ok because core/ubuntu-core have | ||
| // exactly the same profiles and nothing in the generated policies | ||
| // has the core snap-name encoded. | ||
| if _, err := m.reloadConnections(newName); err != nil { | ||
| if _, _, err := m.reloadConnections(newName); err != nil { | ||
| return err | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 know this is super convenient place to put this code, it creates some implicit behaviour of this function that is really not obvious, and should as a minimum be documented. Ideally I'd rather see this as a return value an handled on a task level instead, but I recognize the annoying thing about changing the call chain that also goes through
setupProfilesForAppSetUh oh!
There was an error while loading. Please reload this page.
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.
Just a completely naive thought: is there any reason we don't just cache the all the refreshed snaps connections from "conns" state at the start of Do and restore this during undo?
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.
This isn't wrong, it would be much more explicit. The catch is we don't know which ones are relevant until quite late, so we'd need to collect all of the connections of a snap, along with information on how they were established. Not great but doable. For some snaps, like snapd there's quite a lot of data to be stored this way.
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 pushed a commit renaming some things and adding some comments. I agree that making the task handler itself store this data on the task would be nice, but that would require a pretty large refactor I think?
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 don't think it's that large a refactor, but it's also something we can do at another stage.