Skip to content

Commit 0552a34

Browse files
committed
Fix runner server not respecting max code upload size
1 parent 3d5ab80 commit 0552a34

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

runner/cmd/runner/cmd.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func App() {
1515
var httpPort int
1616
var sshPort int
1717
var logLevel int
18+
var codeUploadLimit int64
1819

1920
app := &cli.App{
2021
Name: "dstack-runner",
@@ -28,6 +29,13 @@ func App() {
2829
Usage: "log verbosity level: 2 (Error), 3 (Warning), 4 (Info), 5 (Debug), 6 (Trace)",
2930
Destination: &logLevel,
3031
},
32+
&cli.Int64Flag{
33+
Name: "code-upload-limit",
34+
Usage: "Set the code upload limit",
35+
Value: 10 * 1024 * 1024,
36+
Destination: &codeUploadLimit,
37+
EnvVars: []string{"DSTACK_RUNNER_CODE_UPLOAD_LIMIT"},
38+
},
3139
},
3240
Commands: []*cli.Command{
3341
{
@@ -66,7 +74,7 @@ func App() {
6674
},
6775
},
6876
Action: func(c *cli.Context) error {
69-
err := start(paths.tempDir, paths.homeDir, paths.workingDir, httpPort, sshPort, logLevel, Version)
77+
err := start(paths.tempDir, paths.homeDir, paths.workingDir, httpPort, sshPort, logLevel, Version, codeUploadLimit)
7078
if err != nil {
7179
return cli.Exit(err, 1)
7280
}

runner/cmd/runner/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func main() {
1919
App()
2020
}
2121

22-
func start(tempDir string, homeDir string, workingDir string, httpPort int, sshPort int, logLevel int, version string) error {
22+
func start(tempDir string, homeDir string, workingDir string, httpPort int, sshPort int, logLevel int, version string, codeUploadLimit int64) error {
2323
if err := os.MkdirAll(tempDir, 0o755); err != nil {
2424
return tracerr.Errorf("Failed to create temp directory: %w", err)
2525
}
@@ -38,7 +38,7 @@ func start(tempDir string, homeDir string, workingDir string, httpPort int, sshP
3838
log.DefaultEntry.Logger.SetOutput(io.MultiWriter(os.Stdout, defaultLogFile))
3939
log.DefaultEntry.Logger.SetLevel(logrus.Level(logLevel))
4040

41-
server, err := api.NewServer(tempDir, homeDir, workingDir, fmt.Sprintf(":%d", httpPort), sshPort, version)
41+
server, err := api.NewServer(tempDir, homeDir, workingDir, fmt.Sprintf(":%d", httpPort), sshPort, version, codeUploadLimit)
4242
if err != nil {
4343
return tracerr.Errorf("Failed to create server: %w", err)
4444
}

runner/internal/runner/api/http.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package api
33
import (
44
"context"
55
"io"
6+
"math"
67
"net/http"
78
"os"
89
"path/filepath"
@@ -64,7 +65,11 @@ func (s *Server) uploadCodePostHandler(w http.ResponseWriter, r *http.Request) (
6465
return nil, &api.Error{Status: http.StatusConflict}
6566
}
6667

67-
r.Body = http.MaxBytesReader(w, r.Body, 10*1024*1024)
68+
if s.codeUploadLimit > 0 {
69+
r.Body = http.MaxBytesReader(w, r.Body, s.codeUploadLimit)
70+
} else {
71+
r.Body = http.MaxBytesReader(w, r.Body, math.MaxInt64)
72+
}
6873
codePath := filepath.Join(s.tempDir, "code") // todo random name?
6974
file, err := os.Create(codePath)
7075
if err != nil {

runner/internal/runner/api/server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ type Server struct {
3131
cancelRun context.CancelFunc
3232

3333
version string
34+
35+
codeUploadLimit int64
3436
}
3537

36-
func NewServer(tempDir string, homeDir string, workingDir string, address string, sshPort int, version string) (*Server, error) {
38+
func NewServer(tempDir string, homeDir string, workingDir string, address string, sshPort int, version string, codeUploadLimit int64) (*Server, error) {
3739
r := api.NewRouter()
3840
ex, err := executor.NewRunExecutor(tempDir, homeDir, workingDir, sshPort)
3941
if err != nil {
@@ -57,6 +59,8 @@ func NewServer(tempDir string, homeDir string, workingDir string, address string
5759
executor: ex,
5860

5961
version: version,
62+
63+
codeUploadLimit: codeUploadLimit,
6064
}
6165
r.AddHandler("GET", "/api/healthcheck", s.healthcheckGetHandler)
6266
r.AddHandler("GET", "/api/metrics", s.metricsGetHandler)

src/dstack/_internal/core/backends/base/compute.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
VolumeProvisioningData,
3939
)
4040
from dstack._internal.core.services import is_valid_dstack_resource_name
41+
from dstack._internal.server.settings import SERVER_CODE_UPLOAD_LIMIT
4142
from dstack._internal.utils.logging import get_logger
4243
from dstack._internal.utils.path import PathLike
4344

@@ -538,6 +539,7 @@ def get_shim_env(
538539
"DSTACK_RUNNER_HTTP_PORT": str(DSTACK_RUNNER_HTTP_PORT),
539540
"DSTACK_RUNNER_SSH_PORT": str(DSTACK_RUNNER_SSH_PORT),
540541
"DSTACK_RUNNER_LOG_LEVEL": log_level,
542+
"DSTACK_RUNNER_CODE_UPLOAD_LIMIT": str(SERVER_CODE_UPLOAD_LIMIT),
541543
"DSTACK_PUBLIC_SSH_KEY": "\n".join(authorized_keys),
542544
}
543545
if backend_shim_env is not None:

0 commit comments

Comments
 (0)