Skip to content

Commit 7855eaa

Browse files
committed
Add abort signal pre-checks to prevent starting cancelled operations
AbortSignal events don't fire retroactively, so if a signal is already aborted when a method is called, the abort listener never fires and the operation runs to completion despite being cancelled. Added pre-checks at operation start in: - SSHRuntime.exec(): Short-circuit before spawning SSH process - SSHRuntime.syncProjectToRemote(): Check at function entry and before bundle spawn This ensures operations cancelled between sequential steps don't start. Addresses Codex feedback.
1 parent d388f1b commit 7855eaa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/runtime/SSHRuntime.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ export class SSHRuntime implements Runtime {
8181
async exec(command: string, options: ExecOptions): Promise<ExecStream> {
8282
const startTime = performance.now();
8383

84+
// Short-circuit if already aborted
85+
if (options.abortSignal?.aborted) {
86+
throw new RuntimeErrorClass("Operation aborted before execution", "exec");
87+
}
88+
8489
// Build command parts
8590
const parts: string[] = [];
8691

@@ -516,6 +521,11 @@ export class SSHRuntime implements Runtime {
516521
initLogger: InitLogger,
517522
abortSignal?: AbortSignal
518523
): Promise<void> {
524+
// Short-circuit if already aborted
525+
if (abortSignal?.aborted) {
526+
throw new Error("Sync operation aborted before starting");
527+
}
528+
519529
// Use timestamp-based bundle path to avoid conflicts (simpler than $$)
520530
const timestamp = Date.now();
521531
const bundleTempPath = `~/.cmux-bundle-${timestamp}.bundle`;
@@ -541,6 +551,12 @@ export class SSHRuntime implements Runtime {
541551
// Step 2: Create bundle locally and pipe to remote file via SSH
542552
initLogger.logStep(`Creating git bundle...`);
543553
await new Promise<void>((resolve, reject) => {
554+
// Check if aborted before spawning
555+
if (abortSignal?.aborted) {
556+
reject(new Error("Bundle creation aborted"));
557+
return;
558+
}
559+
544560
const sshArgs = this.buildSSHArgs(true);
545561
const command = `cd ${shescape.quote(projectPath)} && git bundle create - --all | ssh ${sshArgs.join(" ")} "cat > ${bundleTempPath}"`;
546562

0 commit comments

Comments
 (0)