Skip to content

Dispose components on client disconnects #6693

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 3 commits into from
Jan 15, 2019
Merged

Dispose components on client disconnects #6693

merged 3 commits into from
Jan 15, 2019

Conversation

pranavkm
Copy link
Contributor

Fixes #4047

}
catch
{
// Ignore exceptions thrown by components when they're being disposed.
Copy link
Member

@SteveSandersonMS SteveSandersonMS Jan 15, 2019

Choose a reason for hiding this comment

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

We should log them somehow though, shouldn't we? If someone's disposal logic is failing they will need a way to know about it. This isn't the entire app shutting down, it's just a user closing a browser tab.

Instead of swallowing them, could we capture them all in an AggregateException and then throw it the the end of the upstream Dispose method?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, could you clarify why this code needs to be changed? It doesn't look like it's involved in the circuit teardown process anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went by the comment that suggested something need to be done about exceptions. We can handle this separately


namespace Microsoft.AspNetCore.Components.Server.Circuits
{
public class CircuirHostTest
Copy link
Member

Choose a reason for hiding this comment

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

Typo: CircuitHostTest

Copy link
Member

Choose a reason for hiding this comment

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

Also in filename

}
catch
{
// Ignore failures in components throwing
Copy link
Member

Choose a reason for hiding this comment

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

Although I agree that we shouldn't stop the foreach if there's an exception, I'm not convinced we should be swallowing the exceptions altogether. Do you think it would be reasonable to capture them all in an AggregateException and then throw it at the end of this method?

@@ -1,14 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.AspNetCore.Components.Test.Helpers;
Copy link
Member

Choose a reason for hiding this comment

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

Should we create an editor config so these things stop changing? Our eng guidelines says system first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied over the .editorconfig from MVC. I'll follow up with engg to commonize all the .editorconfigs

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

That was really quick, and mostly looks great!

Let's resolve the questions about exceptions during dispose, then I think it's good to merge.

@@ -1139,6 +1138,21 @@ public async Task CanTriggerEventHandlerDisposedInEarlierPendingBatch()
Assert.Equal(2, numEventsFired);
}

[Fact]
public void DisposingRenderer_DisposesComponents()
Copy link
Member

Choose a reason for hiding this comment

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

It would be great to also have a unit test to show we dispose non-root components too. The first "arrange" section of the CanRenderNestedComponents test shows a convenient way to set up that scenario.

Copy link
Contributor Author

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

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

🆙 :date

@@ -1,14 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.AspNetCore.Components.Test.Helpers;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied over the .editorconfig from MVC. I'll follow up with engg to commonize all the .editorconfigs

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

Looks perfect - thanks for the updates!

if (exceptions != null)
{
throw new AggregateException(exceptions);
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we have an issue somewhere to clean this up? Throwing inside dispose isn't a nice thing to do, especially when you have inheritance involved. There are a bunch of places in this PR that will leak stuff on failed dispose 😆

I realize that you didn't make it worse in this PR, but it is gross so I want to make sure it's on someone's plate to fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it to this issue - #5476

using Moq;
using System;
using System.Threading;
using Xunit;
Copy link
Member

Choose a reason for hiding this comment

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

Sort

@pranavkm pranavkm merged commit b56c589 into master Jan 15, 2019
@pranavkm pranavkm deleted the prkrishn/circuits branch January 15, 2019 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants