Skip to content

fix(Staging-Mode): Close the container if exitStagingMode throws #24775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2025
Merged
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
27 changes: 17 additions & 10 deletions packages/runtime/container-runtime/src/containerRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3474,22 +3474,29 @@ export class ContainerRuntime
throw new UsageError("cannot enter staging mode while detached");
}

// Make sure all BatchManagers are empty before entering staging mode,
// Make sure Outbox is empty before entering staging mode,
// since we mark whole batches as "staged" or not to indicate whether to submit them.
this.outbox.flush();
this.flush();

const exitStagingMode = (discardOrCommit: () => void) => (): void => {
// Final flush of any last staged changes
this.outbox.flush();
try {
// Final flush of any last staged changes
// NOTE: We can't use this.flush() here, because orderSequentially uses StagingMode and in the rollback case we'll hit assert 0x24c
this.outbox.flush();

this.stageControls = undefined;
this.stageControls = undefined;

// During Staging Mode, we avoid submitting any ID Allocation ops (apart from resubmitting pre-staging ops).
// Now that we've exited, we need to submit an ID Allocation op for any IDs that were generated while in Staging Mode.
this.submitIdAllocationOpIfNeeded({ staged: false });
discardOrCommit();
// During Staging Mode, we avoid submitting any ID Allocation ops (apart from resubmitting pre-staging ops).
// Now that we've exited, we need to submit an ID Allocation op for any IDs that were generated while in Staging Mode.
this.submitIdAllocationOpIfNeeded({ staged: false });
discardOrCommit();

this.channelCollection.notifyStagingMode(false);
this.channelCollection.notifyStagingMode(false);
} catch (error) {
const normalizedError = normalizeError(error);
this.closeFn(normalizedError);
throw normalizedError;
}
};

// eslint-disable-next-line import/no-deprecated
Expand Down
Loading