Skip to content

Fix transaction interference in v9 #5205

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
Jul 29, 2021
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Jul 27, 2021

This fixes a bug in listener unregistration, which exists in both the user facing unsubscribe API as well as runTransaction() (since it uses listeners internally).

When we unregister a listener, we go through all existing listeners to find the one that matches. We do this by comparing the callbacks for equality.

In v8, we wrap all listeners, and hence, we have to unwrap the listener to get back to the original user function before checking for equality. Our listener looks as such:

const listener = () => { userCallback(); /*...*/ )
listener.userCallback = userCallback;

In v9, we have:

const listener = userCallback(); 

Unfortunately, the comparison function considered all v9 listeners the same since it either compared listener (which only matches for the exact listener) or listener.userCallback (which matched every listener since the property was never set).

Fixes #5195

@schmidt-sebastian schmidt-sebastian requested a review from jsdt as a code owner July 27, 2021 20:29
@changeset-bot
Copy link

changeset-bot bot commented Jul 27, 2021

⚠️ No Changeset found

Latest commit: e78e813

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions
Copy link
Contributor

Changeset File Check ⚠️

  • Changeset formatting error in following file:
    Package "firebase-compat-typings-test" must depend on the current version of "firebase-exp": "9.0.0-beta.7" vs "file:../../packages-exp/firebase-exp"
    Package "firebase-compat-typings-test" must depend on the current version of "firebase-exp": "9.0.0-beta.7" vs "file:../../packages-exp/firebase-exp"
    Package "firebase-compat-typings-test" must depend on the current version of "firebase-exp": "9.0.0-beta.7" vs "file:../../packages-exp/firebase-exp"
    Some packages have been changed but no changesets were found. Run `changeset add` to resolve this error.
    If this change doesn't need a release, run `changeset add --empty`.
    

Copy link
Contributor

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

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

When there are no changes to comments you don't really need any TW review, but I do approve, thanks! :)

@schmidt-sebastian schmidt-sebastian merged commit ea25b2e into master Jul 29, 2021
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/transactions branch July 29, 2021 23:03
@firebase firebase locked and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: database doc-changes PRs that affect docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

V9 Realtime Database listener stops listening after transaction
4 participants