Open WizX20 opened 4 years ago
I'm having the same issue.
Hi All - I'll be taking a look at this issue today. Are you experiencing this in the 1.0.6 version, or the 2.0.0-alpha1 version?
Following the repro steps on the latest develop branch, I'm seeing this error, and the app hanging as described.
Looks to be 2 issues: 1) The managed ngrok.exe is not shutting down correctly when stopping debugging in VS. It does appear to work correctly though when exiting the console dotnet app via CTRL-C 2) The app hangs when there's an issue with the ngrok process. There's a hard coded time out of 5 minutes, and it appears to work correctly after that time out expires. This behavior should be adjusted to not hang the app, and the timeout made configurable.
Regarding the first part of the issue, when shutting down debugging from VS, it forces shutdown instead of following graceful shutdown, therefore the lifecycle hooks to stop the managed ngrok process do not execute. The end result is an orphaned ngrok process remains after debugging ends. There does not appear to be a workaround in VS to stop this behavior.
The orphaned ngrok process can be found in task manager under a VS debugger console
Relevant issue: https://stackoverflow.com/questions/55499755/gracefully-stopping-asp-net-core-web-app-from-within-visual-studio-debugger-a
I am now using CLI to check if the service is already running, for example:
var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var rootPath = $"{assemblyPath}\\Deployment\\Resources\\Ngrok";
var programName = "ngrok.exe";
// Check if the ngrok service is running.
var findResult = await Cli.Wrap("cmd")
.WithWorkingDirectory(@"C:\Windows\System32")
.WithArguments($"/C TASKLIST | FINDSTR {programName} || START \"\" \"{rootPath}\\{programName}\"")
.ExecuteBufferedAsync();
After some time, the ngrok tunnel is closed by the ngrok serviec itself; I have not yet found a way to detect that.
Could this be the solution? https://stackoverflow.com/questions/3342941/kill-child-process-when-parent-process-is-killed
Marco Regueira's answer.
See the example at: https://github.com/kg73/NgrokAspNetCore/issues/24#issuecomment-621046267
Steps to reproduce (while debugging the example)
var nGrokTunnel = await this.NgrokHostedService?.GetTunnelsAsync();