Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private async Task ProcessMessagesAsync()
int byteCount = encoding.GetBytes(message, buffer);

await _log.WriteAsync(buffer.AsMemory(0, byteCount));
await _log.FlushAsync();
}

async ValueTask RotateFiles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public enum ExitCode { Success = 0, StressError = 1, CliError = 2 };

public static readonly bool IsQuicSupported = QuicListener.IsSupported && QuicConnection.IsSupported;

private static readonly Dictionary<string, int> s_unobservedExceptions = new Dictionary<string, int>();

public static async Task<int> Main(string[] args)
{
if (!TryParseCli(args, out Configuration? config))
Expand Down Expand Up @@ -186,6 +188,25 @@ private static async Task<ExitCode> Run(Configuration config)
Console.WriteLine("Query Parameters: " + config.MaxParameters);
Console.WriteLine();

if (config.RunMode.HasFlag(RunMode.client))
{
TaskScheduler.UnobservedTaskException += (_, e) =>
{
Exception ex = e.Exception;
if (ex is QuicException || ex is AggregateException a && a.InnerExceptions.Any(i => i is QuicException))
{
return;
}

lock (s_unobservedExceptions)
{
string text = ex.ToString();
Console.WriteLine($"Unobserved exception: {e.Exception}");
s_unobservedExceptions[text] = s_unobservedExceptions.GetValueOrDefault(text) + 1;
}
};
}

StressServer? server = null;
if (config.RunMode.HasFlag(RunMode.server))
{
Expand All @@ -210,8 +231,10 @@ private static async Task<ExitCode> Run(Configuration config)
client?.Stop();
client?.PrintFinalReport();

Console.WriteLine($"Unobserved exceptions of {s_unobservedExceptions.Count} different types: {Environment.NewLine}{string.Join(Environment.NewLine + new string('=', 120) + Environment.NewLine, s_unobservedExceptions.Select(pair => $"Count {pair.Value}: {pair.Key}"))}");

// return nonzero status code if there are stress errors
return client?.TotalErrorCount == 0 ? ExitCode.Success : ExitCode.StressError;
return client?.TotalErrorCount == 0 && s_unobservedExceptions.Count == 0 ? ExitCode.Success : ExitCode.StressError;
}

private static async Task WaitUntilMaxExecutionTimeElapsedOrKeyboardInterrupt(TimeSpan? maxExecutionTime = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ public bool TrySetResult(bool final = false)
/// <returns><c>true</c> if this is the first call that set the result; otherwise, <c>false</c>.</returns>
public bool TrySetException(Exception exception, bool final = false)
{
if (exception is QuicException quicException && _keepAlive.IsAllocated)
{
quicException.Sender = _keepAlive.Target;
}
return TryComplete(exception, final);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ internal QuicException(QuicError error, long? applicationErrorCode, long? transp
/// The transport protocol error code associated with the error.
/// </summary>
public long? TransportErrorCode { get; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't merge this particular change, that's just for debugging from where the UOE comes from 😄

internal object? Sender { get; set; }

public override string ToString() => Sender is null ? base.ToString() : $"[{Sender}] {base.ToString()}";
}