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

fix: Route file writing through FileSystem #3614

Merged
merged 19 commits into from
Sep 26, 2024
Merged

fix: Route file writing through FileSystem #3614

merged 19 commits into from
Sep 26, 2024

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Sep 18, 2024

Fixes #3607, getsentry/sentry-unity#1804

Problem

Writing to disk is restricted on platforms like the Switch, causing crashes. There's currently no way to properly opt-out of this. I.e. the SDK creates and tries to persist an ID to disk out-of-the-box.

Solution

  • Adding a new flag to the options: DisableFileWrite.
  • We've already got IFileSystem in place. Making sure to make it is respecting that flag
  • Find all write instances, i.e. File.Create and Directory.Create and replace them with IFileSystem.
  • Tests

TODO

  • Add automatic detection/linting of any use of create, move, and delete` to prevent regressions

src/Sentry/GlobalSessionManager.cs Outdated Show resolved Hide resolved
src/Sentry/GlobalSessionManager.cs Outdated Show resolved Hide resolved
src/Sentry/GlobalSessionManager.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/FileSystem.cs Outdated Show resolved Hide resolved
@bruno-garcia
Copy link
Member

Just realize the strategy with returning bool has an issue. since the caller doesn't know if it failed, or if it's an option picked by the user and will log a bunch of error with the sdk debug logger

You might not be able to hide that all in the file writer abstraction, leaving the knowledge of the option to the callsites and hence skipping the operation altogether.

Or change the interface to return some enum where it can be failure or disabled. Or return null boolean to be simple. and document that null means disable and true/false is the real output

@bitsandfoxes
Copy link
Contributor Author

I'd like to keep the DisableFileWrite check in one place if possible. I think it's going to be much easier to maintain instead of having to check for it in every place the SDK is attempting to write something to disk.
The "failure to write" should be handled regardless of reason by the caller. But I'm adding the null as return value to allow for a more granular handling, i.e. retry or somesuch.

src/Sentry/Internal/FileSystem.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/FileSystem.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/FileSystem.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/FileSystem.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/FileSystem.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/FileSystem.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/FileSystem.cs Outdated Show resolved Hide resolved
Copy link
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

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

LGTM

@bitsandfoxes bitsandfoxes merged commit 2d728ae into main Sep 26, 2024
23 checks passed
@bitsandfoxes bitsandfoxes deleted the fix/filesystem branch September 26, 2024 13:42
using var writer = new Utf8JsonWriter(file);

serializable.WriteTo(writer, logger);
writer.Flush();
file.Dispose();
Copy link
Member

Choose a reason for hiding this comment

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

this couldn’t have using anymore? I’m concerned an exception will keep dangling filesa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolving InstallationId writes to disk by default
4 participants