Skip to content

Attachment silently fails to serialize when using BackgroundWorker on WebGL #600

@ripperdoc

Description

@ripperdoc

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which version of the SDK? 0.10.1

Which version of Unity? 2020.3.23f1

Is this happening in Unity (editor) or on a player like Android, iOS, Windows? On WebGL player

Background

I'm running Sentry on WebGL. Thanks to the new support for IBackgroundWorker to handle the sending of Envelopes, it was easy enough to make Sentry report error events on WebGL. My BackgroundWorker is very simple, it holds a queue and when flushed, it serializes each envelope and sends it using UnityWebRequest. The flushing happens in a coroutine. However, I noticed that user error reports did not work. I found a work around to this, but it may point to some issue in how attachments are handled (or it's just something that would be naturally solved when this SDK gets official WebGL support).

Steps to Reproduce

I have made a repro repo. In short, it's an empty project with Sentry installed. Two keys trigger two different functions in TestCase.cs for attaching a screenshot that is generated (for the user report).

A key triggers code that adds attachment simply with scope.AddAttachment(filePath) which causes Envelope.SerializeAsync to later silently fail.

B key triggers an otherwise identical function that instead attaches the screenshot like this:

using Stream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var data = new byte[fileStream.Length];
fileStream.Read(data, 0, data.Length);
fileStream.Seek(0, SeekOrigin.Begin);
scope.AddAttachment(data, filename);

Clone the repo, go to Assets/TestCase.cs and enter a correct DSN in the code. If you then run this in Editor, it makes no difference whether i press A or B, both works as expected. If I build and run in WebGL, A silently fails but B works.

Here's a sample browser console log that first shows A version, then B version: https://bitbucket.org/fictivr/repro-sentry-unity-attach/src/master/test-case-error-log.txt

No error is seen in the log, two envelopes are queued up in both, but in A, one of the envelopes (the event with attachment) is never sent (SerializeAsync fails such that the web request never gets sent, but I haven't been able to catch any exception - but in WebGL that often doesn't work due to IL2CPP).

What puzzles me is that just opening the file myself and giving the raw data works, while adding the file path fails.

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions