Skip to content

Fix bug that let responsePayloadBytes get set to -1 #6721

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

Merged
merged 3 commits into from
Mar 3, 2025

Conversation

mrober
Copy link
Contributor

@mrober mrober commented Feb 25, 2025

Fix a bug in InstrHttpInputStream that let NetworkRequestMetric.responsePayloadBytes get set to -1 in some conditions.

While investigating b/398063523, I found that inputStream.read(...) can return 0 in some cases, for example, when the byte buffer length is 0. When this happens, it was possible to set responsePayloadBytes to -1 because -1 + 0 = -1. I didn't just have bytesRead initialize to 0 because there is a difference between 0 bytes read, and no read happened. Tested manually by hacking a test app to force this to happen, and by unit tests.

Copy link
Contributor

github-actions bot commented Feb 25, 2025

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Copy link
Contributor

github-actions bot commented Feb 25, 2025

Test Results

  110 files   -  76    110 suites   - 76   2m 18s ⏱️ - 2m 8s
  970 tests  - 265    970 ✅  - 249  0 💤  - 16  0 ❌ ±0 
1 948 runs   - 546  1 948 ✅  - 514  0 💤  - 32  0 ❌ ±0 

Results for commit 529bb6c. ± Comparison against base commit ec26a52.

This pull request removes 1235 and adds 970 tests. Note that renamed tests count towards both.
com.google.firebase.firestore.AggregateQuerySnapshotTest ‑ createWithCountShouldReturnInstanceWithTheGivenQueryAndCount
com.google.firebase.firestore.AggregateQueryTest ‑ testSourceMustNotBeNull
com.google.firebase.firestore.BlobTest ‑ testComparison
com.google.firebase.firestore.BlobTest ‑ testEquals
com.google.firebase.firestore.BlobTest ‑ testMutableBytes
com.google.firebase.firestore.CollectionReferenceTest ‑ testEquals
com.google.firebase.firestore.DocumentChangeTest ‑ randomTests
com.google.firebase.firestore.DocumentChangeTest ‑ testAdditions
com.google.firebase.firestore.DocumentChangeTest ‑ testChangesWithSortOrderChange
com.google.firebase.firestore.DocumentChangeTest ‑ testDeletions
…
com.google.firebase.perf.FirebasePerfRegistrarTest ‑ testGetComponents
com.google.firebase.perf.FirebasePerformanceTest ‑ firebasePerformanceInitialization_providesRcProvider_remoteConfigManagerIsSet
com.google.firebase.perf.FirebasePerformanceTest ‑ initFirebasePerformance_injectsMetadataIntoConfigResolver
com.google.firebase.perf.FirebasePerformanceTest ‑ initializeFirebasePerformance_emptyMetadataAndCache_metadataAndContextInjected
com.google.firebase.perf.FirebasePerformanceTest ‑ setDataCollectionDefaultEnabled_whenForceDisabledThenCleared_respectsGlobalFlag
com.google.firebase.perf.FirebasePerformanceTest ‑ setDataCollectionDefaultEnabled_whenForceDisabledThenCleared_respectsManifestTrue
com.google.firebase.perf.FirebasePerformanceTest ‑ setDataCollectionDefaultEnabled_whenForceEnabledThenCleared_respectsGlobalFlag
com.google.firebase.perf.FirebasePerformanceTest ‑ setDataCollectionDefaultEnabled_whenForceEnabledThenCleared_respectsManifestFalse
com.google.firebase.perf.FirebasePerformanceTest ‑ testAddingMoreThanMaxLocalAttributes
com.google.firebase.perf.FirebasePerformanceTest ‑ testBothManifestsAgree
…

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 25, 2025

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 25, 2025

@mrober mrober merged commit 79deb5f into main Mar 3, 2025
37 checks passed
@mrober mrober deleted the mrober/perf-bytes-read branch March 3, 2025 20:46
tejasd pushed a commit that referenced this pull request Apr 1, 2025
Fix a bug in `InstrHttpInputStream` that let
`NetworkRequestMetric.responsePayloadBytes` get set to -1 in some
conditions.

While investigating [b/398063523](http://b/398063523), I found that
`inputStream.read(...)` can return 0 in some cases, for example, when
the byte buffer length is 0. When this happens, it was possible to set
`responsePayloadBytes` to -1 because `-1 + 0 = -1`. I didn't just have
`bytesRead` initialize to 0 because there is a difference between 0
bytes read, and no read happened. Tested manually by hacking a test app
to force this to happen, and by unit tests.
@firebase firebase locked and limited conversation to collaborators Apr 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants