Closed AlphatronMBS closed 2 years ago
Hi @AlphatronSecurity,
I attempted to replicate this issue with the following program (and a breakpoint set in the catch block in case something happens) however did not encounter an exception after a few minutes of leaving it running
class Program
{
private static PrtgClient client;
static void Main(string[] args)
{
Task.Run(async () => await MainAsync()).Wait();
}
private static async Task MainAsync()
{
client = new PrtgClient("http://prtg.example.com", "prtgadmin", "prtgadmin");
while (true)
await CreateReport("Servers");
}
public static async Task<List<Log>> CreateReport(string GroupName, string probename = null)
{
try
{
if (probename == null)
probename = "Local Probe";
var testgroup = await client.GetGroupsAsync(Property.Probe, FilterOperator.Contains, probename);
var Group = testgroup.Single(x => x.Name == GroupName);
if (Group != null)
{
var test = await client.GetLogsAsync(RecordAge.LastWeek, 500, new LogStatus[] { LogStatus.Down });
return test;
}
else
{
return null;
}
}
catch (Exception ex)
{
return null;
}
}
}
(I had to change how GetLogsAsync
is called as my target group "Servers" didn't have any logs on it)
Are you able to advise if you can replicate the issue using the exact test program above (after modifying the group + probe name and PrtgClient
connection details)
If so, can you please provide the stack trace of the exception as well as the error message + stack trace of any inner exceptions as well
Hello, Thanks for you're quick answere.
I create a new .NET 6.0 console application with a extra counter:
using PrtgAPI;
class Program { private static PrtgClient client;
static void Main(string[] args)
{
Task.Run(async () => await MainAsync()).Wait();
}
private static async Task MainAsync()
{
client = new PrtgClient("http://192.168.34.140/", "prtgadmin", "prtgadmin");
int counter = 0;
while (true)
{
var list = await CreateReport("ANTWERPEN");
Console.WriteLine("list " + list.Count() + " Counter: " + counter);
counter++;
}
}
public static async Task<List<Log>> CreateReport(string GroupName, string probename = null)
{
try
{
if (probename == null)
probename = "Antwerpen (Local Probe)";
var testgroup = await client.GetGroupsAsync(Property.Probe, FilterOperator.Contains, probename);
if (testgroup == null)
{
return null;
}
var Group = testgroup.Single(x => x.Name == GroupName);
if (Group != null)
{
var test = await client.GetLogsAsync(RecordAge.LastWeek, 500, new LogStatus[] { LogStatus.Down });
return test;
}
else
{
return null;
}
}
catch (Exception ex)
{
return null;
}
}
}
on 1567 call's the error thrown
with ex.StackTrace
at System.Net.Http.HttpContent.1.<<GetObjectsRawAsync>b__0>d.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PrtgAPI.Request.ObjectEngine.<ParseInvalidXmlAsync>d__24
1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at PrtgAPI.Request.ObjectEngine.1.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PrtgAPI.PrtgClient.<GetLogsAsync>d__371.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PrtgAPI.PrtgClient.<GetLogsAsync>d__355.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PrtgAPI.PrtgClient.<GetLogsAsync>d__354.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
at Program.
Let me know If you need more information.
Thanks.
I am unable to replicate this using .NET Framework, .NET 5 or .NET 6
Are you able to advise whether you can replicate this
client.GetGroup
/ client.GetLogs
)GetGroupsAsync
or GetLogsAsync
that is failing, so if you can reproduce it only calling one of them (and ideally the synchronous counterpart instead of asynchronous) that will assist in further troubleshooting thisIf you can replicate it using the synchronous API calls, can you please post the stack trace from that
Also can you please post the message/stack trace of any inner exceptions (as well as any inner exceptions inside them, and so on); my understanding is there should be an inner exception of some sort when this error occurs
Hello, In the old test (async) I have here below the inner exception. In my test it will generate very soon the error. I will built the requested test with the sync methodes.
The inner exceptions:
ex._innerException.SerializationStackTraceString: at System.Net.Http.HttpConnection.FillAsync(Boolean async) at System.Net.Http.HttpConnection.CopyToContentLengthAsync(Stream destination, Boolean async, UInt64 length, Int32 bufferSize, CancellationToken cancellationToken) at System.Net.Http.HttpConnection.ContentLengthReadStream.CompleteCopyToAsync(Task copyTask, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionResponseContent.SerializeToStreamAsync(Stream stream, TransportContext context, CancellationToken cancellationToken) at System.Net.Http.HttpContent.LoadIntoBufferAsyncCore(Task serializeToStreamTask, MemoryStream tempBuffer)
Hello,
I think I have the solution.. The Esset Endpoint Security Network attack protection. has been turn on. When I put the program (.net core 6 with async methods) on a clean windows installation it works perfect. (now already 4000 call's without any exception).
Very sorry for that, and thank you for helping me.
Gr. Michiel
Describe the bug
Hello,
I've use the PRTG Client a lot in my program and sometimes I get the exception "Error while copying content to a stream"
I've been seach on the internet:
"Because the controller's ActionFilterAttribute's OnActionExecuting method is calling ReadAsStreamAsync, the Content can't be read again. I changed ReadAsStreamAsync to ReadAsStringAsync and the request's Content is available in the controller. Apparantly, ReadAsStringAsync buffers the Content so it's still available. "
Is this the solution in you're repro or is there something I must change in my program?
Thanks a lot. Michiel.
Steps to reproduce
What is the output of 'Get-PrtgClient -Diagnostic'?
Additional context
No response