Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/orchestrator/pkg/sandbox/envd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ const (
maxEnvdResultBodySize = 1 << 20

// envdErrorBodyRunes is the length, in runes, an error or log line cuts a failed call's body to.
envdErrorBodyRunes = 100
// envd error bodies are short server-generated diagnostics; 512 is enough to keep the actual
// cause of a failure intact (e.g. a volume-mount error carries the full chroot/bind path plus
// the errno text, ~300 chars) instead of cutting it mid-path, while still bounding the body.
envdErrorBodyRunes = 512
// envdErrorBodyLimit is the most of a failed call's body worth reading. Any
// envdErrorBodyRunes runes fit in that many times utf8.UTFMax bytes, and the
// extra byte lets Truncate still tell that a longer body was cut.
Expand Down
8 changes: 6 additions & 2 deletions packages/orchestrator/pkg/sandbox/envd_error_body_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ func TestEnvdErrorBodyMatchesAFullRead(t *testing.T) {
"exactly 100 four-byte runes": strings.Repeat("😀", 100),
"invalid utf-8": strings.Repeat("\xff", 1_000),
"two-byte runes": strings.Repeat("é", 1_000),
// The bug this cap fixes: a volume-mount failure carries the full chroot/bind
// path plus the errno text (~300 chars). At the old 100-rune cap it was cut
// mid-path; at 512 it survives whole.
"volume mount failure (~300 chars)": `/init returned 400: failed to mount "vol-885b": failed to chroot into "/data1/orchestrator/volumes/team-f079aa21-3c4d-4e2a-9b1f-0123456789ab/vol-885b1234-abcd-ef01-2345-6789abcdef01": failed to bind mount "/srv/nfs/team-f079/vol-885b/ws_123.img": no such file or directory`,
} {
t.Run(name, func(t *testing.T) {
t.Parallel()

assert.Equal(t, utils.Truncate(body, 100), envdErrorBody(strings.NewReader(body)))
assert.Equal(t, utils.Truncate(body, envdErrorBodyRunes), envdErrorBody(strings.NewReader(body)))
})
}
}
Expand Down Expand Up @@ -73,7 +77,7 @@ func TestEnvdCallsReadABoundedBody(t *testing.T) {
t.Parallel()

const timeout = 10 * time.Second
truncated := strings.Repeat("e", 97) + "..."
truncated := strings.Repeat("e", envdErrorBodyRunes-len("...")) + "..."

upgradeBin := filepath.Join(t.TempDir(), "envd")
require.NoError(t, os.WriteFile(upgradeBin, []byte("binary"), 0o600))
Expand Down