diff --git a/internal/executor/sandbox/executor.go b/internal/executor/sandbox/executor.go index 4a4cb53..dda11bb 100644 --- a/internal/executor/sandbox/executor.go +++ b/internal/executor/sandbox/executor.go @@ -21,7 +21,6 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { } } // cannot use range loop since we need to change the value - results := make([]stage.ExecutorResult, len(cmds)) for i := 0; i < len(cmds); i += 1 { cmd := &cmds[i] if cmd.CopyIn == nil { @@ -32,25 +31,23 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { cmd.CopyIn[k] = stage.CmdFile{FileID: &fileID} } } - // NOTE: send all cmds at once may cause oom, no idea on why - pbCmd := convertPBCmd([]stage.Cmd{*cmd}) - pbReq := &pb.Request{Cmd: pbCmd} - slog.Debug("sandbox execute", "i", i, "pbReq size", proto.Size(pbReq)) - pbRet, err := e.execClient.Exec(context.TODO(), pbReq) - if err != nil { - return nil, err - } - slog.Debug("sandbox execute", "i", i, "pbRet size", proto.Size(pbRet)) - if pbRet.Error != "" { - return nil, fmt.Errorf("sandbox execute error: %s", pbRet.Error) - } - if len(pbRet.Results) == 0 { - return nil, fmt.Errorf("sandbox execute error: no result") - } - result := convertPBResult(pbRet.Results)[0] - slog.Debug("sandbox execute", "i", i, "result", result) + } + pbCmds := convertPBCmd(cmds) + for i, pbCmd := range pbCmds { + slog.Debug("sandbox execute", "i", i, "pbCmd size", proto.Size(pbCmd)) + } + pbReq := &pb.Request{Cmd: pbCmds} + slog.Debug("sandbox execute", "pbReq size", proto.Size(pbReq)) + pbRet, err := e.execClient.Exec(context.TODO(), pbReq) + if err != nil { + return nil, err + } + if pbRet.Error != "" { + return nil, fmt.Errorf("sandbox execute error: %s", pbRet.Error) + } + results := convertPBResult(pbRet.Results) + for _, result := range results { maps.Copy(e.cachedMap, result.FileIDs) - results[i] = result } return results, nil }