Skip to content

[Spa] Try additional hooks to kill the application #34427

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
Aug 17, 2021

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Jul 16, 2021

Try a couple of additional hooks for killing the SPA proxy.

We got a report that the services remain alive after the debugger has stopped the process. The changes included here are the only two meaningful differences with the previous implemenation (here)

@ghost ghost added the area-runtime label Jul 16, 2021
@javiercn javiercn requested review from HaoK and removed request for Tratcher and BrennanConroy July 16, 2021 17:01
Copy link
Contributor

@mkArtakMSFT mkArtakMSFT left a comment

Choose a reason for hiding this comment

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

Thanks @javiercn.
This fix isn't bad at all. I think this very well be the long term fix that we need.

IOptions<SpaDevelopmentServerOptions> options)
{
_options = options.Value;
_logger = logger;
appLifetime.ApplicationStopping.Register(() => Dispose(true));
Copy link
Member

Choose a reason for hiding this comment

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

So SpaProxyLaunchManager is a service in DI but Dispose isn't getting called on app shutdown for some reason?

Who normally calls StopAsync?

Do you want to use ApplicationStopped instead? Requests may still be in flight otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Tratcher the problem here is that the debugger kills the app and leaves the process running.

We don't get a chance to kill the SPA process ourselves. This change just brings the current implementation more inline with the old implementation, although I suspect both suffer from the same issue.

Copy link
Member

Choose a reason for hiding this comment

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

If I recall correctly, the debugger kills processes in the rudest way possible with no chance to run shutdown logic. What you really need is a way to register the child process with the debugger as something it should also terminate. Maybe if you launched the child process with the debugger attached?

https://docs.microsoft.com/en-us/visualstudio/debugger/debug-multiple-processes?view=vs-2019#stop-debugging-with-multiple-processes

I see some prior art here:
#5204
#11597
#17883 (claims ApplicationStopping worked for them)

Copy link
Member Author

Choose a reason for hiding this comment

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

None of this things work, people thought they worked because they didn't see the window (or didn't try with the debugger).

I found a reasonable solution which is simple enough I'm happy with. We launch a powershell process that monitors the .NET process and when it sees it die, it kills the npm process and all its children, and that does the trick.

@javiercn javiercn force-pushed the javiercn/spa-dispose-harder branch from 5dcc39f to 44416ed Compare August 17, 2021 16:14
@javiercn javiercn merged commit c894584 into main Aug 17, 2021
@javiercn javiercn deleted the javiercn/spa-dispose-harder branch August 17, 2021 19:59
@ghost ghost added this to the 6.0-rc1 milestone Aug 17, 2021
@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visual studio not terminating node.js processes after ending a debug session of .net apps
4 participants