-
Notifications
You must be signed in to change notification settings - Fork 141
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
Don't listen for the Console_CancelKeyPress #1323
Conversation
Flushing and closing the tracer on cancel key press can lead to flushing the buffer before the app has finished writing spans. CurrentDomain_ProcessExit should always fire, so flushing twice is unnecessary
If we do this, we should probably remove it from |
I did a simple test and the behavior changes: The current code with some Console.WriteLine...Behavior:But if I stop listeing the Ctrl+C handler and comment the code:Behavior:Here
|
I wonder then if this behavior can also happen in the tracer, because then we should handle both calls and prepare the tracer for both calls, 1 only flush, 1 flush + close. |
Unless I'm misunderstanding, this seems really weird @tonyredondo? Why wouldn't the
This seems like a reasonable approach anyway tbh. i.e. keep the |
It doesn't fire If I hit CTRL+C. In a normal exit it will. Although I saw this:
For (1) I think is a problem with the dotnet CLI related to this issue (dotnet/sdk#4779) I don't know if (2) affect us.
👍🏻 |
So:
Source code:
|
Ah, so in a .NET Core app, they handle the console key press and do a normal exit, so that might explain the difference with what we're seeing I guess?
Urgh, going to be so many edge-cases here... So what's the danger if we only call I'm also wondering how this would work in (for example) Kubernetes. There the container gets As I understand it, in that case, we would get the |
Yeah I think this can be caused by a bug in the .NET CLI.
S C A R Y
I think we should do that, //
// Summary:
// Gets or sets a value that indicates whether simultaneously pressing the System.ConsoleModifiers.Control
// modifier key and the System.ConsoleKey.C console key (Ctrl+C) or the Ctrl+Break
// keys terminates the current process. The default is false, which terminates the
// current process.
//
// Returns:
// true if the current process should resume when the event handler concludes; false
// if the current process should terminate. The default value is false; the current
// process terminates when the event handler returns. If true, the current process
// continues.
public bool Cancel { get; set; } I think we can control the behavior by setting this to
Maybe I'm missing something but if we are already handling the |
That seems like a dangerous thing for us to be messing with in people's apps though 😟 I feel like we're just stuck with handling the various combinations that could happen.
The point is that we will get the e.g. Timeline of events:
|
Yes, you're right, I agree we shouldn't be playing with the customer app behavior.
Oh now I get it!. Yes we have a problem here... hooking to |
Closing this for now as this is overly simplistic and ignores other edge cases. @tonyredondo is looking at an alternative, more robust, approach playing with the |
Flushing and closing the tracer on cancel key press can lead to flushing the buffer before the app has finished writing spans.
CurrentDomain_ProcessExit
should always fire and flush, so flushing twice is unnecessaryAs an example repro, create a new service worker using
dotnet new worker
, and update worker.cs to:Run the app, see the requests being made, and hit
ctrl-c
. The traces are not sent, as thebackground-service
operation is closed after the Tracer is close and flushed@DataDog/apm-dotnet