Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Feature/database errors #85

Merged
merged 1 commit into from
Jan 11, 2017
Merged

Feature/database errors #85

merged 1 commit into from
Jan 11, 2017

Conversation

charlesmchen
Copy link
Contributor

@charlesmchen charlesmchen commented Jan 6, 2017

@@ -92,24 +110,52 @@ + (instancetype)sharedManager {
- (instancetype)initDefault
{
self = [super init];

if (![self tryToLoadDatabase]) {
// Failing to load the database is a catastrophic.
Copy link
Contributor

Choose a reason for hiding this comment

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

you a word again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// or the keychain has become corrupt. Either way, we want to get back to a
// "known good state" and behave like a new install.

BOOL shouldHavePassword = [[NSUserDefaults standardUserDefaults] objectForKey:TSStorageManagerHasDatabasePassword];
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 using fileExistsAtPath would get you the same information and save a couple lines farther down. It might even be more conceptually to-the-point since that's the file that this password corresponds to.

not a blocking concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, you're right. I was trying to avoid filesystem access, but "less state = more surface area for bugs."

}

[self deletePasswordFromKeychain];
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before:

We are missing the call to [TSAttachmentStream deleteAttachments]; which deletes any on-disk attachments. Instead of these lines, wipeSignalStorage is almost what we want but won't work as is.

Copy link
Contributor Author

@charlesmchen charlesmchen Jan 6, 2017

Choose a reason for hiding this comment

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

Yup, see above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although... as discussed offline, I think we should convert our "media/blob" cache to a LRU cache where contents get evacuated based on some maximum size on disk. My understanding is that the app disk usage currently grows in an unbounded way, which is:

  • Burdensome on/troublesome for users.
  • A vector of serious "out of disk space" bugs.

Many users keep their phones very close to full at all times.

OWSAnalyticsCritical(@"Could not load database");

// Try to reset app by deleting database.
[self deletePasswordFromKeychain];
Copy link
Contributor

Choose a reason for hiding this comment

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

We are missing the call to [TSAttachmentStream deleteAttachments]; which deletes any on-disk attachments. Instead of these lines, wipeSignalStorage is almost what we want but won't work as is - though see below for my comment there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I split wipeSignalStorage into two methods to DRY this up.

[TSAttachmentStream deleteAttachments];

[[self init] setupDatabase];
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 even think this setupDatabase bit is necessary, so maybe you could use this in multiple places above if you just remove this line.

It's unnecessary, since (IIRC) the only place this is called, we immediately kill the app. In which case the database would be setup on next launch. (Users access this functionality in Settings > Delete Account)

Though should we be killing the app is a different question. Probably not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh! Also, why was this calling init?!? I'm going to take your suggestion remove this line and undo the "splitting" I mentioned above.

// We determine the database password first, since a side effect of
// this can be deleting any existing database file (if we're recovering
// from a corrupt keychain).
NSData *databasePassword = [self databasePassword];
Copy link
Contributor

Choose a reason for hiding this comment

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

You know. THIS change made me curious, and I found out we were calling the cipher block which queries the keychain 25 times in quick succession on startup. =/

@charlesmchen
Copy link
Contributor Author

PTAL @michaelkirk

//
// OWSAnalytics.h
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

wanna run precommit on all these?

Copy link
Contributor

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -24,7 +24,7 @@ extern NSString *const TSUIDatabaseConnectionDidUpdateNotification;
- (void)setupDatabase;
- (void)deleteThreadsAndMessages;
- (BOOL)databasePasswordAccessible;
- (void)wipeSignalStorage;
- (void)resetSignalStorage;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a heads up that this is used in Signal-iOS. Generally if there are breaking changes in ssk, try to open the corresponding Signal-iOS PR that can run it simultaneously.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

self.database = nil;
_dbConnection = nil;
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer property getters wherever possible (even internally). My rationale is that some assumptions become easier when only getters, setters, dealloc, and init touch it.

I could be persuaded to always use ivars internally, but I don't think we should mix and match arbitrarily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that sounds quite reasonable. In fact, the only reason I accessed the ivar here is because this property is declared as readonly in the header and there's no readwrite property as one might expect in a private anonymous category. Going forward I'll fix these as I find them!

charlesmchen added a commit to signalapp/Signal-iOS that referenced this pull request Jan 11, 2017
charlesmchen added a commit to signalapp/Signal-iOS that referenced this pull request Jan 11, 2017
@charlesmchen charlesmchen merged commit c5cf79c into master Jan 11, 2017
@charlesmchen charlesmchen deleted the feature/databaseErrors branch January 11, 2017 22:13
charlesmchen added a commit to signalapp/Signal-iOS that referenced this pull request Jan 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants