Skip to content
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

feat(Container): Add IContainer.closedWithError to access the error that closed or disposed the container #23364

Merged
merged 8 commits into from
Dec 19, 2024

Conversation

markfields
Copy link
Member

@markfields markfields commented Dec 18, 2024

Description

Fixes AB#13773

Two cases I know of where one would want to be able to inspect a closed container to see what the error was:

  • A race condition where the container closes while Container.load is returning it (interleaved microtasks), so the "closed" event never fires and the error is not thrown.
  • If another API is called after the container is closed, resulting in a UsageError, and the caller didn't expect the container to be closed and wants to know why (for debugging or telemetry purposes)

Breaking Changes

Nope, it's adding an optional property to an interface.

Reviewer Guidance

@microsoft/fluid-cr-api -- Please provide feedback / suggestions on the naming and semantics of this new API. I tried to keep it simple, at the cost of some ambiguity in corner cases (e.g. when you close and dispose with different errors).

@markfields markfields requested review from Copilot and kian-thompson and removed request for Copilot December 18, 2024 22:50
@github-actions github-actions bot added area: loader Loader related issues area: tests Tests to add, test infrastructure improvements, etc base: main PRs targeted against main branch labels Dec 18, 2024
@markfields markfields requested a review from a team as a code owner December 18, 2024 22:52
@github-actions github-actions bot added the public api change Changes to a public API label Dec 18, 2024
@markfields markfields requested review from a team, pragya91, jatgarg, tyler-cai-microsoft, rajatch-ff and MarioJGMsoft and removed request for a team December 18, 2024 22:52
category: !this.closed && error !== undefined ? "error" : "generic",
// Use error category if there's an error, unless we already closed with an error (i.e. _criticalError is set)
category:
error !== undefined && this._criticalError === undefined ? "error" : "generic",
Copy link
Contributor

Choose a reason for hiding this comment

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

why change this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm thinking that the closed state is a legit (non-error) state for a container to be in, if it was closed with no error (consider the fact that we wouldn't log that "ContainerClosed" event as an error). Then if it's disposed with an error, that'd be the point where we'd want to see the error log.

i.e. if you close (no error) then dispose (with error), before you would get no error logs. Now you do get an error log.

@markfields markfields requested a review from a team as a code owner December 18, 2024 23:35
// When disposing with an error...
// - if we closed with an error, _criticalError doesn't expose the dispose error.
// - if we closed without an error, _criticalError doesn't distinguish whether this error came from close or dispose.
this._criticalError ??= error;
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly to pushing the other set of this variable, i also wonder if this should be done higher up. i also wonder if we should only set if is undefined, and the container is not closed. this would make some of the caveats above go away, as this would always represent the error the container is closed with.

the only difference is that if the container is previously closed without error, this closeWithError will never be set, which makes sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

only set if is undefined, and the container is not closed

I thought about that, but I think if dispose can take an error, we should be able to access it this way.

(This is also part of why I didn't name it with the term close at first)

Copy link
Contributor

@anthony-murphy anthony-murphy Dec 19, 2024

Choose a reason for hiding this comment

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

i think i would be willing to lose the dispose error when closed without error, the case seems uncommon, and removing it keeps everything consistent.

in fact, inspecting the container object after dispose isn't really supported, as dispose should mean all usage is done, and we don't guarantee anything about the state after that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Chatted offline. In conclusion, I'm going to switch it as suggested. Key reasoning:

I'm adding this to fill a particular gap, in the Container Load flow. And this corner case is not relevant there. So if someone is very concerned about getting the dispose error, they will have the event to listen to. And... why are you using a container after handling the dispose event anyway

Copy link
Contributor

@alexvy86 alexvy86 left a comment

Choose a reason for hiding this comment

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

Left a couple of docs-related comments; otherwise looks good from that standpoint. I did notice some of the comment threads say they are addressed but apparently aren't yet (maybe commits that haven't been pushed?).

.changeset/busy-mangos-ask.md Show resolved Hide resolved
packages/loader/container-loader/src/container.ts Outdated Show resolved Hide resolved
@markfields
Copy link
Member Author

@anthony-murphy -- I just pushed, this is ready for final review. Thanks for the help on this one!

Copy link
Contributor

🔗 No broken links found! ✅

Your attention to detail is admirable.

linkcheck output


> fluid-framework-docs-site@0.0.0 ci:check-links /home/runner/work/FluidFramework/FluidFramework/docs
> start-server-and-test "npm run serve -- --no-open" 3000 check-links

1: starting server using command "npm run serve -- --no-open"
and when url "[ 'http://127.0.0.1:3000' ]" is responding with HTTP status code 200
running tests using command "npm run check-links"


> fluid-framework-docs-site@0.0.0 serve
> docusaurus serve --no-open

[SUCCESS] Serving "build" directory at: http://localhost:3000/

> fluid-framework-docs-site@0.0.0 check-links
> linkcheck http://localhost:3000 --skip-file skipped-urls.txt

Crawling...

Stats:
  170138 links
    1596 destination URLs
    1825 URLs ignored
       0 warnings
       0 errors


@anthony-murphy anthony-murphy changed the title feat(Container): Add IContainer.criticalError to access the error that closed or disposed the container feat(Container): Add IContainer.closedWithError to access the error that closed or disposed the container Dec 19, 2024
},
);

itExpects(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. end to end test are costly to run and maintain, did you consider a unit test, or a local-server test?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great point. I started by trying to unit test... there are NO existing unit tests for Container class! So decided not to be the tip of that spear. Local-server only is a good idea though. Probably most of this file should be local-server only.

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out all these e2e tests only run against local, so that's good. We could move them to local-server-tests though at some point

@markfields markfields merged commit 711d05a into microsoft:main Dec 19, 2024
42 checks passed
@markfields markfields deleted the container-close-prop branch December 19, 2024 22:28
jikim-msft added a commit that referenced this pull request Dec 23, 2024
… error that closed or disposed the container" (#23399)

#### Description
 
Reverts #23364


This change appears to cause errors in our end to end stress tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: loader Loader related issues area: tests Tests to add, test infrastructure improvements, etc base: main PRs targeted against main branch changeset-present public api change Changes to a public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants