Repository navigation
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. |
|
Please see the following code review and address at least the test gap: Assessment of PR #179: "Fix
|
|
Thanks for the review. Updated in 34b10a6:
The initializer is declared for tests in a class extension in Unit tests pass locally on iOS: 113 tests. Not run on tvOS, macOS or Catalyst. Edited after amending the commit. An earlier version described a settable property. |
14f0cbd to
b1c63ba
Compare
Make the application used for the GDTStorage background task injectable, as GDTCORTransformer does: GDTCORFlatFileStorage gets a readonly `application` property and -initWithApplication:, and -init passes +[GDTCORApplication sharedApplication]. -storeEvent:onComplete: captures the application once per call, so begin, the expiration handler and end use the same instance. Tests declare the initializer in a class extension in GDTCORFlatFileStorage+Testing.h. Declaring it in the (Testing) category triggers -Wincomplete-implementation. Add three tests that create their own storage instance with GDTCORApplicationFake. A stored event, an event dropped because the storage size limit is reached, and an event whose write fails each begin and end the task exactly once with the identifier returned on begin. Without the fix in the previous commit, the size-limit and write-failure tests fail on the unfulfilled "Background task end" expectation. The write fails because a regular file occupies the event's directory path. The dropped event carries a 1 KB payload, so it cannot fit in the space left after filling the storage. The encode-failure branch is not tested: a real event always archives, so reaching it would need a test-only event class that opts out of NSSecureCoding. testInit checks that the shared and new instances use the shared application. Also remove an outdated comment at the top of the storage block.
b1c63ba to
34b10a6
Compare
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
GDTCORFlatFileStorageTest(second commit), using the existingGDTCORApplicationFake:testStoreEvent_WhenSizeLimitReached_ThenBackgroundTaskIsEnded,testStoreEvent_WhenWritingFails_ThenBackgroundTaskIsEndedandtestStoreEvent_WhenEventIsWritten_ThenBackgroundTaskIsEndedexpect theGDTStoragetask to begin once and end once with the identifier returned on begin. With the
failure-path end calls removed, the size-limit and write-failure tests fail on the
unfulfilled "Background task end" expectation.
GoogleDataTransport-Unit-Tests-Uniton the iOS simulator:113 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
GDTCORFlatFileStoragetakes the application through-initWithApplication:, asGDTCORTransformerdoes.-initpasses+[GDTCORApplication sharedApplication]and the property is readonly. The tests createtheir own instance with
GDTCORApplicationFake; the initializer is declared for them ina class extension in
GDTCORFlatFileStorage+Testing.h. Production behaviour isunchanged apart from the fix.
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.1 and on
mainat5d20ca19); iPhone 17 simulator, iOS 26.0,Xcode 26.0 (17A324). Unit tests on
mainat5d20ca19plus this PR; iPhone 18 Prosimulator, iOS 27.2, Xcode 27.2 (27B52), with
IPHONEOS_DEPLOYMENT_TARGET=15.0because Xcode 27.2 rejects the pods' 9.0/12.0 deployment targets. Style checked with
clang-format 23.1.5.