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

Filestore thread safety fixes #295

Merged
merged 10 commits into from
Apr 30, 2018
Merged

Filestore thread safety fixes #295

merged 10 commits into from
Apr 30, 2018

Conversation

fractalwrench
Copy link
Contributor

@fractalwrench fractalwrench commented Apr 23, 2018

We sometimes receive invalid payloads with an empty/malformed array where an error/session should be - e.g. [] or [,]. My hypothesis is that this occurs when the max limit of Error/Sessions are cached on disk. When the app is relaunched, if write is called just before the payload is serialised, then this can lead to the oldest File being deleted, which means there is no data to serialise.

This attempts to address this scenario by retaining a reference to any Files which are currently being flushed, and not deleting them.

A potential downside to this implementation is that it currently requires manually calling cancelQueuedFiles and deleteStoredFiles, which could be forgotten.

moves code to delete files to single method within filestore
acquire a lock when writing/deleting files directly from the filestore
only deletes stored files if they are not already queued for a request
@fractalwrench fractalwrench requested a review from a team April 23, 2018 14:20
@coveralls
Copy link

Pull Request Test Coverage Report for Build 1331

  • 20 of 39 (51.28%) changed or added relevant lines in 3 files are covered.
  • 18 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.5%) to 73.513%

Changes Missing Coverage Covered Lines Changed/Added Lines %
sdk/src/main/java/com/bugsnag/android/ErrorStore.java 1 3 33.33%
sdk/src/main/java/com/bugsnag/android/SessionTracker.java 0 3 0.0%
sdk/src/main/java/com/bugsnag/android/FileStore.java 19 33 57.58%
Files with Coverage Reduction New Missed Lines %
sdk/src/main/java/com/bugsnag/android/DeviceData.java 2 76.69%
sdk/src/main/java/com/bugsnag/android/Client.java 3 58.74%
sdk/src/main/java/com/bugsnag/android/SessionTracker.java 13 59.23%
Totals Coverage Status
Change from base Build 1322: -0.5%
Covered Lines: 1854
Relevant Lines: 2522

💛 - Coveralls

1 similar comment
@coveralls
Copy link

Pull Request Test Coverage Report for Build 1331

  • 20 of 39 (51.28%) changed or added relevant lines in 3 files are covered.
  • 18 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.5%) to 73.513%

Changes Missing Coverage Covered Lines Changed/Added Lines %
sdk/src/main/java/com/bugsnag/android/ErrorStore.java 1 3 33.33%
sdk/src/main/java/com/bugsnag/android/SessionTracker.java 0 3 0.0%
sdk/src/main/java/com/bugsnag/android/FileStore.java 19 33 57.58%
Files with Coverage Reduction New Missed Lines %
sdk/src/main/java/com/bugsnag/android/DeviceData.java 2 76.69%
sdk/src/main/java/com/bugsnag/android/Client.java 3 58.74%
sdk/src/main/java/com/bugsnag/android/SessionTracker.java 13 59.23%
Totals Coverage Status
Change from base Build 1322: -0.5%
Covered Lines: 1854
Relevant Lines: 2522

💛 - Coveralls

@coveralls
Copy link

coveralls commented Apr 23, 2018

Coverage Status

Coverage increased (+0.6%) to 75.296% when pulling 1dab5ce on filestore-thread-safety into dbb069f on next.

@fractalwrench fractalwrench changed the base branch from master to next April 23, 2018 14:54
@fractalwrench fractalwrench changed the base branch from next to master April 23, 2018 14:54
adds tests for basic functionality of newly added methods
@fractalwrench fractalwrench changed the title [WIP] Filestore thread safety fixes Filestore thread safety fixes Apr 25, 2018
@fractalwrench fractalwrench changed the base branch from master to next April 25, 2018 15:46
iterate through files and delete unqueued files if the max storage limit is reached
initialises a filestore directly in unit tests, rather than relying on the client. this should
reduce side effects (e.g. error flushing on launch) which may have led to flakiness
provide a null check in the unlikely case the collection param is null
@fractalwrench
Copy link
Contributor Author

@bugsnag/platforms this is now ready for review.

@@ -82,26 +100,63 @@ String write(@NonNull T streamable) {
filename), exception);
} finally {
IOUtils.closeQuietly(out);
lock.unlock();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a chance this can fail if IOUtils throws?

Copy link
Contributor

Choose a reason for hiding this comment

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

NVM, I just looked up what IOUtils.closeQuietly does

Copy link
Contributor

@Cawllec Cawllec left a comment

Choose a reason for hiding this comment

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

LGTM, but I'm not overly familiar with either Java or this notifier so @Pezzah would you be able to get a look in?

}
return null;
}

@NonNull abstract String getFilename(T streamable);
@NonNull
abstract String getFilename(T streamable);

List<File> findStoredFiles() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be called multiple times in the current design, which might cause bad things to happen. Potentially this should only return files that are not already in the queued files set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I've updated this method so that it only returns stored files which aren't in the queuedFiles collection.

finding stored files in filestore should now only return files which are not currently enqueued.
this prevents bad things happening if a delivery client looks up files twice for example, and
attempts to send duplicate reports.
@fractalwrench fractalwrench merged commit a4ff17f into next Apr 30, 2018
@fractalwrench fractalwrench deleted the filestore-thread-safety branch April 30, 2018 12:57
lemnik pushed a commit that referenced this pull request Jun 2, 2021
Fix bugsnag.sharedObjectPaths not uploading SO files
rich-bugsnag pushed a commit that referenced this pull request Sep 3, 2021
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.

4 participants