Skip to content

Commit

Permalink
cmd/microcloud: Trigger StopSession API calls to the joiner members i…
Browse files Browse the repository at this point in the history
…f the initiator does not finish properly after initiating a session

Signed-off-by: Gabriel Mougard <gabriel.mougard@canonical.com>
  • Loading branch information
gabrielmougard committed Dec 3, 2024
1 parent 3a36ff1 commit 8555b38
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/microcloud/main_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,32 @@ func (c *initConfig) RunInteractive(cmd *cobra.Command, args []string) error {
services[s.Type()] = version
}

var reverter *revert.Reverter
if c.setupMany {
err = c.runSession(context.Background(), s, types.SessionInitiating, c.sessionTimeout, func(gw *cloudClient.WebsocketGateway) error {
return c.initiatingSession(gw, s, services, "", nil)
})
if err != nil {
return err
}

reverter = revert.New()
defer reverter.Fail()

reverter.Add(func() {
// Stop each joiner member session.
cloud := s.Services[types.MicroCloud].(*service.CloudService)
for peer, system := range c.systems {
if system.ServerInfo.Name == "" || system.ServerInfo.Name == c.name {
continue
}

err = cloud.StopJoinerSession(context.Background(), system.ServerInfo.Address, "Initiator cluster member aborted")
if err != nil {
logger.Error("Failed to stop joiner session", logger.Ctx{"joiner": peer, "error": err})
}
}
})
}

state, err := s.CollectSystemInformation(context.Background(), multicast.ServerInfo{Name: c.name, Address: c.address, Services: services})
Expand Down Expand Up @@ -282,6 +301,10 @@ func (c *initConfig) RunInteractive(cmd *cobra.Command, args []string) error {
return err
}

if c.setupMany {
reverter.Success()
}

return nil
}

Expand Down

0 comments on commit 8555b38

Please sign in to comment.