mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
NOISSUE - Prevent race conditions on manager (#316)
* fix panic Signed-off-by: Sammy Oina <sammyoina@gmail.com> * no races Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
This commit is contained in:
committed by
GitHub
parent
77d99d4beb
commit
d70bf052a5
@@ -67,7 +67,7 @@ func (ms *managerService) FetchAttestationPolicy(_ context.Context, computationI
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if measurement == nil {
|
||||
if measurement != nil {
|
||||
attestationPolicy.Policy.Measurement = measurement
|
||||
}
|
||||
|
||||
|
||||
+11
-5
@@ -117,6 +117,10 @@ func New(cfg qemu.Config, attestationPolicyBinPath string, logger *slog.Logger,
|
||||
}
|
||||
|
||||
func (ms *managerService) Run(ctx context.Context, c *ComputationRunReq) (string, error) {
|
||||
ms.mu.Lock()
|
||||
cfg := ms.qemuCfg
|
||||
ms.mu.Unlock()
|
||||
|
||||
ms.publishEvent(manager.VmProvision.String(), c.Id, manager.Starting.String(), json.RawMessage{})
|
||||
ac := agent.Computation{
|
||||
ID: c.Id,
|
||||
@@ -157,7 +161,7 @@ func (ms *managerService) Run(ctx context.Context, c *ComputationRunReq) (string
|
||||
ms.publishEvent(manager.VmProvision.String(), c.Id, agent.Failed.String(), json.RawMessage{})
|
||||
return "", errors.Wrap(ErrFailedToAllocatePort, err)
|
||||
}
|
||||
ms.qemuCfg.HostFwdAgent = agentPort
|
||||
cfg.HostFwdAgent = agentPort
|
||||
|
||||
var cid int = qemu.BaseGuestCID
|
||||
for {
|
||||
@@ -173,7 +177,7 @@ func (ms *managerService) Run(ctx context.Context, c *ComputationRunReq) (string
|
||||
}
|
||||
cid++
|
||||
}
|
||||
ms.qemuCfg.VSockConfig.GuestCID = cid
|
||||
cfg.VSockConfig.GuestCID = cid
|
||||
|
||||
ch, err := computationHash(ac)
|
||||
if err != nil {
|
||||
@@ -182,9 +186,9 @@ func (ms *managerService) Run(ctx context.Context, c *ComputationRunReq) (string
|
||||
}
|
||||
|
||||
// Define host-data value of QEMU for SEV-SNP, with a base64 encoding of the computation hash.
|
||||
ms.qemuCfg.SevConfig.HostData = base64.StdEncoding.EncodeToString(ch[:])
|
||||
cfg.SevConfig.HostData = base64.StdEncoding.EncodeToString(ch[:])
|
||||
|
||||
cvm := ms.vmFactory(ms.qemuCfg, ms.eventsLogsSender, c.Id)
|
||||
cvm := ms.vmFactory(cfg, ms.eventsLogsSender, c.Id)
|
||||
ms.publishEvent(manager.VmProvision.String(), c.Id, agent.InProgress.String(), json.RawMessage{})
|
||||
if err = cvm.Start(); err != nil {
|
||||
ms.publishEvent(manager.VmProvision.String(), c.Id, agent.Failed.String(), json.RawMessage{})
|
||||
@@ -198,7 +202,7 @@ func (ms *managerService) Run(ctx context.Context, c *ComputationRunReq) (string
|
||||
|
||||
state := qemu.VMState{
|
||||
ID: c.Id,
|
||||
Config: ms.qemuCfg,
|
||||
Config: cfg,
|
||||
PID: pid,
|
||||
}
|
||||
if err := ms.persistence.SaveVM(state); err != nil {
|
||||
@@ -212,9 +216,11 @@ func (ms *managerService) Run(ctx context.Context, c *ComputationRunReq) (string
|
||||
return "", err
|
||||
}
|
||||
|
||||
ms.mu.Lock()
|
||||
if err := ms.vms[c.Id].Transition(manager.VmRunning); err != nil {
|
||||
ms.logger.Warn("Failed to transition VM state", "computation", c.Id, "error", err)
|
||||
}
|
||||
ms.mu.Unlock()
|
||||
|
||||
ms.publishEvent(manager.VmProvision.String(), c.Id, agent.Completed.String(), json.RawMessage{})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user