Skip to content

fix(NLog): Correct task tracking to prevent dropped logs on shutdown#15561

Open
robertvoinescu-work wants to merge 1 commit intogoogleapis:mainfrom
robertvoinescu-work:nlog/stackDriverFailure
Open

fix(NLog): Correct task tracking to prevent dropped logs on shutdown#15561
robertvoinescu-work wants to merge 1 commit intogoogleapis:mainfrom
robertvoinescu-work:nlog/stackDriverFailure

Conversation

@robertvoinescu-work
Copy link
Copy Markdown
Contributor

@robertvoinescu-work robertvoinescu-work commented Apr 9, 2026

Fixes an issue where WriteLogEntries tasks were tracked incorrectly due to mixing .ContinueWith with async/await. This premature completion caused logs to be dropped during application shutdown. See inline comments for details.

Validation

  • Tests: Added tests to prevent regression.
  • Manual Verification: Tested by logging two consecutive messages followed by an immediate application shutdown.

Before fix: The second message is dropped because the task is killed.
image

After fix: Both messages upload successfully.
image

b/450286403

@robertvoinescu-work robertvoinescu-work requested a review from a team as a code owner April 9, 2026 22:12
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue where log entries could be dropped during shutdown because the Flush method did not correctly await all pending asynchronous uploads. The fix involves adding .Unwrap() to the task chaining logic in GoogleStackdriverTarget.cs, ensuring that _prevTask tracks the actual completion of the gRPC upload rather than just the initiation of the task. Additionally, a new unit test Flush_AwaitsAllTasks has been added to verify that Flush properly waits for chained uploads. I have no feedback to provide as the changes are correct and well-tested.

@robertvoinescu-work robertvoinescu-work force-pushed the nlog/stackDriverFailure branch 4 times, most recently from 144d6ad to 95da5b3 Compare April 10, 2026 18:28
@robertvoinescu-work robertvoinescu-work changed the title fix(NLog): Correct task tracking with an unwrap to prevent dropped logs on shutdown fix(NLog): Correct task tracking to prevent dropped logs on shutdown Apr 10, 2026
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.

1 participant