Skip to content

Commit

Permalink
fix concurrency big in coordinator
Browse files Browse the repository at this point in the history
Signed-off-by: Plamen Petrov <plamb0brt@gmail.com>
  • Loading branch information
plamenmpetrov committed Nov 12, 2020
1 parent bf4e632 commit 1d4d5c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cri/container_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *CriService) RemoveContainer(ctx context.Context, r *criapi.RemoveContai
containerID := r.GetContainerId()

go func() {
if err := s.coordinator.stopVM(ctx, containerID); err != nil {
if err := s.coordinator.stopVM(context.Background(), containerID); err != nil {
log.WithError(err).Error("failed to stop microVM")
}
}()
Expand Down
17 changes: 12 additions & 5 deletions cri/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@ func (c *coordinator) stopVM(ctx context.Context, containerID string) error {
c.Lock()

vmID, ok := c.activeVMs[containerID]
c.Unlock()
if !ok {
c.Unlock()
return nil
}

c.free(containerID, vmID)
c.Unlock()

return c.orchStopVM(ctx, vmID)
err := c.orchStopVM(ctx, vmID)
if err != nil {
log.WithError(err).Error("coordinator failed to stop VM")
return err
}

c.free(containerID, vmID)
return nil
}

func (c *coordinator) insertMapping(containerID, vmID string) error {
Expand Down Expand Up @@ -138,6 +141,10 @@ func (c *coordinator) free(containerID, vmID string) {
if err != nil {
log.Panic("provided non-int id")
}

c.Lock()
defer c.Unlock()

delete(c.activeVMs, containerID)
c.availableIDs = append(c.availableIDs, i)
}
Expand Down

0 comments on commit 1d4d5c0

Please sign in to comment.