Skip to content

[Heartbeat Service] More null service protections added to triggerHeartBeat #7789

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 13 commits into from
Nov 22, 2023

Conversation

DellaBitta
Copy link
Contributor

Discussion

Users are reporting furhter issues with the heartbeat service returning a null cache on Opera. There's a case in triggerHeartBeat which the code assumes that the cache was created properly.

Add a check to ensure that the cache exists, and if not, returns immediately.

Testing

CI.

API Changes

N/A.

Copy link

changeset-bot bot commented Nov 16, 2023

🦋 Changeset detected

Latest commit: e2a206a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/app Patch
@firebase/app-compat Patch
firebase Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 16, 2023

Size Report 1

Affected Products

  • @firebase/app

    TypeBase (a5c1a35)Merge (cebd4de)Diff
    browser14.5 kB14.7 kB+198 B (+1.4%)
    esm519.0 kB19.2 kB+220 B (+1.2%)
    main19.9 kB20.1 kB+220 B (+1.1%)
    module14.5 kB14.7 kB+198 B (+1.4%)
  • bundle

    43 size changes

    TypeBase (a5c1a35)Merge (cebd4de)Diff
    analytics (logEvent)43.9 kB44.0 kB+143 B (+0.3%)
    app-check (CustomProvider)36.7 kB36.8 kB+143 B (+0.4%)
    app-check (ReCaptchaEnterpriseProvider)39.2 kB39.3 kB+143 B (+0.4%)
    app-check (ReCaptchaV3Provider)39.2 kB39.3 kB+143 B (+0.4%)
    auth (Anonymous)73.6 kB73.7 kB+143 B (+0.2%)
    auth (EmailAndPassword)81.4 kB81.6 kB+143 B (+0.2%)
    auth (GoogleFBTwitterGitHubPopup)100 kB100 kB+143 B (+0.1%)
    auth (GooglePopup)97.4 kB97.6 kB+143 B (+0.1%)
    auth (GoogleRedirect)97.6 kB97.8 kB+143 B (+0.1%)
    auth (Phone)83.8 kB84.0 kB+143 B (+0.2%)
    database (Append to a list of data)148 kB148 kB+143 B (+0.1%)
    database (Filtering data)147 kB147 kB+143 B (+0.1%)
    database (Listen for child events)164 kB164 kB+143 B (+0.1%)
    database (Listen for value events + Detach listeners)164 kB164 kB+143 B (+0.1%)
    database (Listen for value events)164 kB164 kB+143 B (+0.1%)
    database (Read data once)163 kB163 kB+143 B (+0.1%)
    database (Save data as transactions)166 kB166 kB+143 B (+0.1%)
    database (Sort data)149 kB149 kB+143 B (+0.1%)
    database (Write data)148 kB148 kB+143 B (+0.1%)
    firestore (Persistence)302 kB302 kB+143 B (+0.0%)
    firestore (Query Cursors)238 kB238 kB+143 B (+0.1%)
    firestore (Query)236 kB236 kB+143 B (+0.1%)
    firestore (Read data once)224 kB224 kB+143 B (+0.1%)
    firestore (Realtime updates)226 kB226 kB+143 B (+0.1%)
    firestore (Transaction)204 kB204 kB+143 B (+0.1%)
    firestore (Write data)204 kB204 kB+143 B (+0.1%)
    firestore-lite (Query Cursors)88.9 kB89.1 kB+143 B (+0.2%)
    firestore-lite (Query)85.1 kB85.2 kB+143 B (+0.2%)
    firestore-lite (Read data once)61.4 kB61.5 kB+143 B (+0.2%)
    firestore-lite (Transaction)86.3 kB86.4 kB+143 B (+0.2%)
    firestore-lite (Write data)71.0 kB71.1 kB+143 B (+0.2%)
    functions (call)31.3 kB31.4 kB+143 B (+0.5%)
    messaging (send + receive)46.6 kB46.8 kB+143 B (+0.3%)
    performance (trace)51.1 kB51.2 kB+143 B (+0.3%)
    remote-config (getAndFetch)45.6 kB45.8 kB+143 B (+0.3%)
    storage (getBytes)41.4 kB41.5 kB+143 B (+0.3%)
    storage (getDownloadURL)43.5 kB43.6 kB+143 B (+0.3%)
    storage (getMetadata)42.9 kB43.1 kB+143 B (+0.3%)
    storage (list + listAll)42.3 kB42.5 kB+143 B (+0.3%)
    storage (updateMetadata)43.2 kB43.3 kB+143 B (+0.3%)
    storage (uploadBytes)48.0 kB48.2 kB+143 B (+0.3%)
    storage (uploadBytesResumable)58.0 kB58.1 kB+143 B (+0.2%)
    storage (uploadString)48.2 kB48.4 kB+143 B (+0.3%)

  • firebase

    TypeBase (a5c1a35)Merge (cebd4de)Diff
    firebase-app-compat.js29.0 kB29.2 kB+130 B (+0.4%)
    firebase-app.js93.5 kB94.0 kB+439 B (+0.5%)
    firebase-compat.js778 kB779 kB+130 B (+0.0%)
    firebase-performance-standalone-compat.es2017.js90.2 kB90.4 kB+116 B (+0.1%)
    firebase-performance-standalone-compat.js67.4 kB67.5 kB+139 B (+0.2%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/95pnKKiy4M.html

@DellaBitta DellaBitta requested a review from hsubox76 November 16, 2023 16:36
@DellaBitta DellaBitta marked this pull request as ready for review November 16, 2023 16:36
@DellaBitta DellaBitta requested a review from a team as a code owner November 16, 2023 16:36
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 16, 2023

Size Analysis Report 1

This report is too large (141,122 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/eE5RDTsPsn.html

@@ -90,6 +90,10 @@ export class HeartbeatServiceImpl implements HeartbeatService {
const date = getUTCDateString();
if (this._heartbeatsCache?.heartbeats == null) {
this._heartbeatsCache = await this._heartbeatsCachePromise;
// If we failed to construct a heartbeats cache, then return immediately.
if (this._heartbeatsCache?.heartbeats == null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hsubox76 perhaps this should just check if heartbeatsCache === null?

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 the root problem is here:

return idbHeartbeatObject || { heartbeats: [] };
or even one function back (readHeartbeatsFromIndexedDB). It's checking to see if whatever comes back from indexedDB is falsy but if it's (as I suspect) an empty object, this will go wrong. We have to make sure that whatever gets returned from this read() function is an object with a heartbeats property which is an array (e.g., matches type HeartbeatsInIndexedDB), otherwise we are lying to typescript and so it can't protect us by catching errors further downstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I updated the read() method (below) to ensure the returned object has a heartbeats field.

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 think this check should be needed anymore after the other change but I guess it doesn't hurt to be safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I feel like keeping it place just in case.

@DellaBitta DellaBitta requested review from a team as code owners November 20, 2023 16:46
@@ -90,6 +90,10 @@ export class HeartbeatServiceImpl implements HeartbeatService {
const date = getUTCDateString();
if (this._heartbeatsCache?.heartbeats == null) {
this._heartbeatsCache = await this._heartbeatsCachePromise;
// If we failed to construct a heartbeats cache, then return immediately.
if (this._heartbeatsCache?.heartbeats == null) {
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 think this check should be needed anymore after the other change but I guess it doesn't hurt to be safe.

Copy link
Contributor

github-actions bot commented Nov 20, 2023

Changeset File Check ✅

  • No modified packages are missing from the changeset file.
  • No changeset formatting errors detected.

@DellaBitta DellaBitta merged commit e9ff107 into master Nov 22, 2023
@DellaBitta DellaBitta deleted the ddb-heartbeatcache-checks branch November 22, 2023 20:16
@google-oss-bot google-oss-bot mentioned this pull request Nov 22, 2023
@firebase firebase locked and limited conversation to collaborators Dec 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants