Skip to content

Change how EndSegment is called for Tasks #197

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 1 commit into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Enables nullable reference types that are part of the C# 8.0 language specificat

### Fixes
* Fixes an issue that may cause `InvalidCastException` due to an assembly version mismatch in Mvc3 instrumentation.
* Fixes an async timing issue that can cause the end time of `Task`-returning methods to be determined incorrectly.

## [8.31] - 2020-08-17
### New Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,18 @@ private static void OnSuccess<T>(Task task, IAgent agent, ISegment segment, bool
transaction.Hold();
}

if (options == TaskContinueWithOption.None)
if (task.IsCompleted)
{
EndSegment(task);
}
else if (options == TaskContinueWithOption.None)
{
if (!continuationOptions.HasValue) task.ContinueWith(EndSegment);
else task.ContinueWith(EndSegment, continuationOptions.Value);
}
else
{
var context = SynchronizationContext.Current;
if (context != null)
{
task.ContinueWith(EndSegment, TaskScheduler.FromCurrentSynchronizationContext());
}
else
{
task.ContinueWith(EndSegment, TaskContinuationOptions.ExecuteSynchronously);
}
task.ContinueWith(EndSegment, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}

void EndSegment(Task completedTask)
Expand Down