Skip to content
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

Fixed envelopes with large attachments persist on disk #3328

Merged
merged 4 commits into from
Apr 29, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- `HttpResponse.Content` is no longer disposed by when using `SentryHttpFailedRequestHandler` on .NET Framework, which was causing an ObjectDisposedException when using Sentry with NSwag ([#3306](https://github.com/getsentry/sentry-dotnet/pull/3306))
- Fix BackgroundWorker exiting when OperationCanceledException is not from shutdown request ([3284](https://github.com/getsentry/sentry-dotnet/pull/3284))
- Envelopes with large attachments no longer get stuck in the queue when using `CacheDirectoryPath` ([#3328](https://github.com/getsentry/sentry-dotnet/pull/3328))

## 4.4.0

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Http/HttpTransportBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void ProcessEnvelopeItem(DateTimeOffset now, EnvelopeItem item, List<Env

// If attachment, needs to respect attachment size limit
if (string.Equals(item.TryGetType(), "attachment", StringComparison.OrdinalIgnoreCase) &&
item.TryGetLength() > _options.MaxAttachmentSize)
item.TryGetOrRecalculateLength() > _options.MaxAttachmentSize)
{
// note: attachment drops are not currently counted in discarded events

Expand Down
15 changes: 15 additions & 0 deletions src/Sentry/Protocol/Envelopes/EnvelopeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ public EnvelopeItem(IReadOnlyDictionary<string, object?> header, ISerializable p
var value => Convert.ToInt64(value) // can be int, long, or another numeric type
};

internal long? TryGetOrRecalculateLength()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand how we get here or how that fixes the issue - even if it does (which I believe).
The attachment size did not get read correctly from the header? How/why not? Should it have been set in the first place? And if we're recalculating it here, should it not end up being set now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd put all of that in the details for the issue itself... but I just moved it into the details of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

So the length ends up in the header during serialization and gets removed during deserialization because of trust-issues. Fair enough.
But is this not a bug in the caching transport then? Should the length not be set back on the header during serialization?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not trying to bikeshed here, I genuinely don't get how it works.

Copy link
Collaborator Author

@jamescrosswell jamescrosswell Apr 25, 2024

Choose a reason for hiding this comment

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

Yeah you have to read Matt's PR in order to understand where the length is being calcluated now.

{
if (TryGetLength() is { } headerLength)
{
return headerLength;
}

if (Payload is StreamSerializable streamSerializable)
{
return streamSerializable.Source.TryGetLength();
}

return null;
}

/// <summary>
/// Returns the file name or null if no name exists.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Tests/Protocol/Envelopes/EnvelopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,8 @@ public async Task Roundtrip_WithEvent_WithAttachment_Success()
.Which.Source.Should().BeEquivalentTo(@event);

envelopeRoundtrip.Items[1].Payload.Should().BeOfType<StreamSerializable>();
envelopeRoundtrip.Items[1].TryGetLength().Should().BeNull();
envelopeRoundtrip.Items[1].TryGetOrRecalculateLength().Should().Be(attachment.Content.GetStream().Length);
}

[Fact]
Expand Down
Loading