-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix empty byte[] bug in EventSource #52602
Conversation
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue Details#52092 switched from a for loop to Since One such case was in This PR
cc: @karelz
|
This comment has been minimized.
This comment has been minimized.
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are hitting #52596 |
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Outdated
Show resolved
Hide resolved
if (data->Size == 0) | ||
{ | ||
decoded = Array.Empty<byte>(); | ||
} | ||
else | ||
{ | ||
var blob = new byte[data->Size]; | ||
Marshal.Copy(data->DataPointer, blob, 0, blob.Length); | ||
decoded = blob; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be simpler and safer as:
decoded = new Span<byte>((byte*)data->DataPointer, data->Size).ToArray();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is what I had used initially, but it sadly involves duplicating the logic under #if #else
as EventSource
is also being built standalone (no Span)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not reference the netstandard span package from the downlevel solution?
Either way, I don't think we should penalize the latest platform because of the source sharing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brianrob, we still maintain/ship the separate EventSource package? Who uses that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way, I don't think we should penalize the latest platform because of the source sharing.
100% agree with this.
Who uses that?
This periodically comes up (see: #32276 (comment)). This is building this package, which is used to ship EventSource features out-of-band for older framework releases. Download counts have been dwindling since 2015. The 5.0 version has ~320k downloads in 7 months.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which is used to ship EventSource features out-of-band for older framework releases
Are we still adding new EventSource features it's important to be able to release in this vehicle? Can we just stop shipping new versions of it? If it's about bug fixes as Brian mentions in the linked comment, can we just treat it as servicing and fix bugs out of release/5.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with moving that to a servicing life cycle. Brian has a better sense of what impact that would have though, so I would defer to his input before ripping it out.
CC @noahfalk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EventSource package is really used for two things:
- Ship new features out-of-band for older frameworks.
- Ship bug fixes out-of-band for older frameworks.
The package only targets .NET Framework, so anything for .NET Core would just go through the standard servicing process. It's not clear to me that we're adding new features to EventSource at a rate that really requires the package - for me, the question is really whether or not we need a relief valve to be able to fix issues on .NET Framework. If we can do that through a servicing release, then that's fine, but I worry that .NET 5 will only be supported for so long and then we lose the infrastructure and shipping support for this. Over time, as we move folks towards .NET Core, this package becomes less and less important, but I don't think we're in a place where we'll be ready in a year or two to just stop producing the package, even through servicing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a relief valve to be able to fix issues on .NET Framework
To make sure I understand, this doesn't actually unify with what's in .NET Framework, right? Someone has to explicitly switch from using the EventSource in .NET Framework to this differently namespaced type in the OOB?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's right - it does not unify. Someone will have to explicitly consume the NuGet package. The namespace is also different - Microsoft.Diagnostics.Tracing
instead of System.Diagnostics.Tracing
.
#52092 switched from a for loop to
Marshal.Copy
when copying data to abyte[]
.Since
fixed
will return a null ptr for empty arrays and custom event implementations may not have this guard against that, we end up callingMarshal.Copy(NULL, ... length: 0)
.One such case was in
NetEventSource.DumpBuffer
.This PR
length != 0
check before callingMarshal.Copy
and adds morebyte[]
/byte*
testscc: @karelz