-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Debug proxy as external tool #19767
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
Debug proxy as external tool #19767
Conversation
src/Components/WebAssembly/testassets/HostedInAspNet.Server/Properties/launchSettings.json
Show resolved
Hide resolved
{ | ||
public void Configure(IApplicationBuilder app, DebugProxyOptions debugProxyOptions) | ||
{ | ||
app.UseDeveloperExceptionPage(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseExceptionHandler
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why. The developer exception page provides useful diagnostic info, and this is a development-time feature only.
return await tcs.Task; | ||
} | ||
|
||
private static void RemoveUnwantedEnvironmentVariables(IDictionary<string, string> environment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have @Tratcher review this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but unless that happens particularly quickly, let's not block the initial merge on it.
It does make sense not to pass through the ASPNETCORE_*
env vars (since we don't want the child process to try using the same ports as the parent, for example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have the list of environment variables before filtering? That would help us understand which ones we should remove and which ones we should preserve, but I believe they all should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You fully control the process being started, correct? In that case it would be cleaner to control the config from within that app. E.g. Don't use Host.CreateDefaultBuilder
in that app and never add environment variables as a config source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Tratcher. We'll track your suggestions as follow up items
<Target Name="IncludeDebugProxyBinariesAsContent" BeforeTargets="GetCopyToOutputDirectoryItems"> | ||
<ItemGroup> | ||
<DebugProxyBinaries Include="..\..\DebugProxy\src\bin\$(Configuration)\$(DefaultNetCoreTargetFramework)\**" /> | ||
<ContentWithTargetPath Include="@(DebugProxyBinaries)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels very strange. Is there a reason the tool couldn't carry a copy of the proxy so it's not in the build output of the project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See option 2 in the PR description.
Do we need to setup CTI tests for this? |
} | ||
} | ||
|
||
private static async Task<string> LaunchAndGetUrl(IServiceProvider serviceProvider) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I suggest that instead or relying on the Regexes (given that we control the proxy) we define on the server a "ready" endpoint and pass that down to the proxy and have the proxy send an Http request back to the server to indicate it's up and running? That way we avoid having to depend on regexes and reading console output and I think we would have a more reliable solution.
We can actually do this for keeping the process alive too, by passing in a "keep alive" endpoint that the proxy can ping to determine if the launcher process is still alive and terminate itself after a defined period of time if that's not the case. That way you don't just rely on the parent PID (which although is very rare, can be reused sometimes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to not do that unless it becomes necessary. That would be yet more moving parts and a more complex polling system.
The approach of regexing console output is pretty commonplace for this purpose. We did it for NodeServices where it's continued to work fine for many years, plus we do it in our tests. VS Code does the same thing too when launching ASP.NET Core and connecting the debugger.
We don't need to keep the process alive. It stays alive on its own. We're using the parent's PID only when starting up the listener, and thereafter we attach to the Exited
event which is designed for this scenario.
If any of this turns out to be inadequate in real use I'm very open to changing it, but current have no reason to think there are realistic drawbacks to this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a lot of context on the finer level details, but overall I agree with your solution and your changes look good.
If we end up not launching the debugger after May, then I'm not that worried about the specific mechanics we do for now.
…only, not a compile-time dependency in sources.
This reverts commit fa64728.
…ds polluting Solution Explorer.
Co-Authored-By: Pranav K <[email protected]>
Co-Authored-By: Pranav K <[email protected]>
40d0e40
to
b031b74
Compare
Implements #19702 and #19144
The list of commits makes this look more complicated than it is, because I tried out several approaches in sequence. It's only worth reviewing the final state. (Nonetheless it is still quite complicated, which is inherent to what we have to do here.)
One of the main design questions in this was how to get the debug proxy binaries into a place we can find them at runtime. I tried out all of the following approaches:
Actually having a compile-time reference from
M.A.C.WA.Server
toM.A.C.WA.DebugProxy
. This means .NET Core itself will take care of getting the debug proxy assemblies into the output directory and locating them at runtime.Newtonsoft.Json
andMono.Cecil
) become real transitive dependencies of customers' "hosted" server projects, which makes no sense and could interfere if they want to use different versions of those packages.Keeping the binaries inside the
M.A.C.WA.DebugProxy
package directory. I added some MSBuild stuff that, during build, writes out the location of that package directory as a file into the build output dir. At runtime we read that file.Writing the binaries to the output directory in an independent subfolder.
<Content>
items in the M.A.C.WA.Server package).If we want to change any aspects of this in the future we certainly can, but we won't have time to get too tied up about it for the preview 3 release.
Future follow-ups could include: