Skip to content

fix(container-runtime): Always close the container if ContainerRuntime.flush throws#24318

Merged
markfields merged 3 commits intomicrosoft:mainfrom
markfields:cr/flush-close
Apr 11, 2025
Merged

fix(container-runtime): Always close the container if ContainerRuntime.flush throws#24318
markfields merged 3 commits intomicrosoft:mainfrom
markfields:cr/flush-close

Conversation

@markfields
Copy link
Copy Markdown
Member

@markfields markfields commented Apr 10, 2025

Description

Flush is often called from secondary callstacks such that an error thrown will not propagate up to user code. However, failure to flush is a fatal error that we cannot recover from.

This change adds a try-catch to ContainerRuntime.flush to ensure that the container is always closed if an error is thrown. I also went through all the errors thrown underneath there and made some tweaks to make them easier to interpret. e.g. using DataProcessingError more, since this is an error type we expect consumers to monitor closely (we wouldn't want an app to sweep these flush errors under the rug).

Copilot AI review requested due to automatic review settings April 10, 2025 20:00
@github-actions github-actions Bot added area: runtime Runtime related issues base: main PRs targeted against main branch labels Apr 10, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

} catch (newError: unknown) {
if ((newError as Partial<Error>).message === "Invalid string length") {
} catch (error: unknown) {
if ((error as Partial<Error>).message === "Invalid string length") {
Copy link

Copilot AI Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Comparing the error message string directly may be brittle across different environments or future updates. Consider checking for the error type or a more robust property to determine if the error is due to string length issues.

Suggested change
if ((error as Partial<Error>).message === "Invalid string length") {
if ((error as Partial<Error>).name === "RangeError") {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Not going to change this now.

Comment thread packages/runtime/container-runtime/src/containerRuntime.ts
@github-actions github-actions Bot added the area: tests Tests to add, test infrastructure improvements, etc label Apr 10, 2025
Copy link
Copy Markdown
Contributor

@MarioJGMsoft MarioJGMsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@markfields markfields merged commit f37a823 into microsoft:main Apr 11, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Runtime related issues area: tests Tests to add, test infrastructure improvements, etc base: main PRs targeted against main branch Feature_StagingMode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants