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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -173,7 +174,7 @@ private void hydrateWithArchive(KubernetesSandboxState state, InputStream archiv
// Phase 1: Stream archive to a temp file via stdin.
// "cat" exits immediately on EOF — no post-EOF work, no SIGKILL race.
ByteArrayOutputStream errBuf = new ByteArrayOutputStream();
Integer uploadCode;
CompletableFuture<Integer> uploadExit;
try (ExecWatch watch =
pod(state)
.redirectingInput()
Expand All @@ -182,21 +183,22 @@ private void hydrateWithArchive(KubernetesSandboxState state, InputStream archiv
try (OutputStream stdin = watch.getInput()) {
archive.transferTo(stdin);
}
try {
uploadCode = watch.exitCode().get(TAR_TIMEOUT_SECONDS + 10L, TimeUnit.SECONDS);
} catch (java.util.concurrent.TimeoutException e) {
uploadExit = watch.exitCode();
}
try {
Integer code = uploadExit.get(TAR_TIMEOUT_SECONDS + 10L, TimeUnit.SECONDS);
if (code != null && code != 0) {
throw new SandboxException.SandboxRuntimeException(
SandboxErrorCode.WORKSPACE_ARCHIVE_READ_ERROR,
"archive upload to pod timed out");
"archive upload failed (exit="
+ code
+ "): "
+ errBuf.toString(StandardCharsets.UTF_8));
}
}
if (uploadCode == null || uploadCode != 0) {
} catch (java.util.concurrent.TimeoutException e) {
throw new SandboxException.SandboxRuntimeException(
SandboxErrorCode.WORKSPACE_ARCHIVE_READ_ERROR,
"archive upload failed (exit="
+ uploadCode
+ "): "
+ errBuf.toString(StandardCharsets.UTF_8));
"archive upload to pod timed out");
}

// Phase 2: Extract from the temp file — no stdin involved, no race.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void tarWorkspaceIn_success_exitCodeZero() throws Exception {
}

@Test
void tarWorkspaceIn_uploadExitNull_throwsException() {
void tarWorkspaceIn_uploadExitNull_isTreatedAsSuccess() throws Exception {
ContainerResource container = mock(ContainerResource.class);
doReturn(container).when(podResource).inContainer(anyString());

Expand All @@ -203,11 +203,9 @@ void tarWorkspaceIn_uploadExitNull_throwsException() {
doReturn(execWatch).when(writingErrExec).exec(anyString(), anyString(), anyString());
doReturn(CompletableFuture.completedFuture(0)).when(execWatch).exitCode();

assertThrows(
SandboxException.SandboxRuntimeException.class,
() ->
runtime.tarWorkspaceIn(
createK8sState(), new ByteArrayInputStream("data".getBytes())));
// Null exit code is expected when Websocket closes before stream 3 status arrives.
// The upload itself completed successfully — null should be treated as success.
runtime.tarWorkspaceIn(createK8sState(), new ByteArrayInputStream("data".getBytes()));
}

@Test
Expand Down
Loading