Fix GDTStorage background task not being ended on storeEvent: failure paths - #179
Open
tilltue wants to merge 1 commit into
Open
Fix GDTStorage background task not being ended on storeEvent: failure paths#179tilltue wants to merge 1 commit into
GDTStorage background task not being ended on storeEvent: failure paths#179tilltue wants to merge 1 commit into
Conversation
… paths -[GDTCORFlatFileStorage storeEvent:onComplete:] begins a "GDTStorage" background task before dispatching to the storage queue. Outside the expiration handler, only the success path ended it: the three early returns inside the dispatched block (encode failure, storage size limit reached, write failure) returned without ending it, leaving the assertion outstanding until the system expired it. Once the storage directory reaches kGDTCORFlatFileStorageSizeLimit, every subsequent store attempt takes the size-limit branch, so no attempt releases its assertion. Extract the teardown into an endBackgroundTaskIfNeeded block and call it on each exit path. The success-path teardown point is unchanged: it still runs after the size tracker update and the high-QoS upload trigger. Related: firebase/firebase-ios-sdk#15129
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
-[GDTCORFlatFileStorage storeEvent:onComplete:]begins aGDTStoragebackground task,but the three failure paths inside the dispatched block (encode failure, storage size
limit reached, write failure) return without ending it. While the tracked storage size
is at or over
kGDTCORFlatFileStorageSizeLimit, every successfully encoded event takesthe size-limit branch, so no store attempt releases its assertion until the system
expires it.
GoogleDataTransport/GoogleDataTransport/GDTCORLibrary/GDTCORFlatFileStorage.m
Lines 128 to 192 in 5d20ca1
This change ends the task on every exit path. The success-path teardown point is
unchanged (still after the size tracker update and the high-QoS upload trigger).
Related: firebase/firebase-ios-sdk#15129 (currently closed,
needs-info). Filling thestorage past the limit gives a deterministic way to exercise the leaking path (steps
below).
Testing
GoogleDataTransport-Unit-Tests-Uniton the iOSsimulator: 110 tests, 0 failures.
every
GDTStoragetask created during the run was left un-ended and produced the"was created over 30 seconds ago" warning; after this change all were ended.
Reproduction steps and measurements
Library/Caches/google-sdks-events/(a sparse file is enough —
GDTCORDirectorySizeTrackersumsNSURLFileSizeKey;e.g.
mkfile -n 21m filler).log stream --predicate 'eventMessage CONTAINS "GDTStorage"'.My counts of
Created background task/Ending task with identifierover 150 sforeground runs:
main@5d20ca19, baselinemain@5d20ca19, over limitmain@5d20ca19, filler removedNotes
injectable, as
GDTCORTransformerdoes, which I did not want to bundle with the fix.Happy to add it if preferred.
bgIDis accessed from the expiration handler and_storageQueuewithoutsynchronisation. This is pre-existing (the success path already had it, and
GDTCORTransformerhas the same pattern); the failure paths now share it. I canfollow up separately if you would like that addressed.
-testLanguage en -testRegion USbecausetestFetchAndUpdateMetrics_WhenDecodeErrorcompares an EnglishlocalizedFailureReasonand fails on a non-English host regardless of this change.Not run locally: tvOS/macOS/Catalyst/watchOS, Thread Sanitizer.
storeEvent:onComplete:unchanged in 10.1.1and on
mainat5d20ca19); iPhone 17 simulator, iOS 26.0, Xcode 26.0 (17A324).