Page MenuHomePhabricator

Implement sanity check for semaphore for flat-file based message storage
AbandonedPublic

Authored by marcin on Jun 29 2022, 2:46 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 11, 7:33 PM
Unknown Object (File)
Mon, Nov 11, 4:34 PM
Unknown Object (File)
Mon, Nov 11, 3:49 PM
Unknown Object (File)
Mon, Nov 11, 12:28 PM
Unknown Object (File)
Mon, Nov 11, 9:14 AM
Unknown Object (File)
Mon, Nov 11, 3:55 AM
Unknown Object (File)
Oct 26 2024, 11:01 AM
Unknown Object (File)
Oct 23 2024, 6:45 AM

Details

Summary

Implement utility method that ensures semaphore is in healthy state.

Test Plan

No test plan.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

Introduce files to project.pbxproj

tomek requested changes to this revision.Jul 5 2022, 3:49 AM
tomek added inline comments.
native/ios/Comm/TemporalMessageStorage/TemporalMessageStorage.mm
142–155

Maybe we should enhance this method by trying to acquire and immediately release the lock? If that succeeds, the lock is fine.

This revision now requires changes to proceed.Jul 5 2022, 3:49 AM
native/ios/Comm/TemporalMessageStorage/TemporalMessageStorage.mm
142

If a method starts with ensure, the expectation is that it checks the state and fix it if it was invalid. In this case, we only check the state and not fix it, so instead we should use e.g. check

marcin requested review of this revision.Jul 5 2022, 6:49 AM
marcin added inline comments.
native/ios/Comm/TemporalMessageStorage/TemporalMessageStorage.mm
142

If semaphore gets broken and number of random files grows large this method will remove it so that next call that tries to acquire semaphore will create new one that will work fine so in my opinion it fixes the state if it is not valid.

142–155

The only case in which storageContents.count > randomFilesNumberThreshold is true and semaphore is fine is that NotificationService attempted to write many messages (20) exactly when AppDelegate was reading which is quite unlikely. We can be almost certain that if number of random files grows large the semaphore is broken. Making an additional check by trying to acquire it will introduce additional possibility for the semaphore to be left broken (if NotificationService gets killed before it releases the lock).

New algorithm makes method introduced by this diff irrelevant.