这是indexloc提供的服务,不要输入任何密码
Skip to content

Firestore: Make ListenerRegistration::Remove() thread-safe #10065

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 5 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased
- [fixed] Fixed an intermittent crash if `ListenerRegistration::Remove()` was
invoked concurrently (#10065).

# 9.4.0
- [fixed] Fixed a crash during app start (#9985, #10018).

Expand Down
3 changes: 3 additions & 0 deletions Firestore/core/src/api/query_listener_registration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Firestore/core/src/core/firestore_client.h"
#include "Firestore/core/src/core/query_listener.h"
#include "Firestore/core/src/core/view_snapshot.h"
#include "absl/synchronization/mutex.h"

namespace firebase {
namespace firestore {
Expand All @@ -38,6 +39,8 @@ QueryListenerRegistration::QueryListenerRegistration(
}

void QueryListenerRegistration::Remove() {
absl::MutexLock lock(&mutex_);

auto async_listener = async_listener_.lock();
if (async_listener) {
async_listener->Mute();
Expand Down
11 changes: 8 additions & 3 deletions Firestore/core/src/api/query_listener_registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "Firestore/core/src/api/listener_registration.h"
#include "Firestore/core/src/core/core_fwd.h"
#include "absl/base/thread_annotations.h"
#include "absl/synchronization/mutex.h"

namespace firebase {
namespace firestore {
Expand All @@ -44,14 +46,17 @@ class QueryListenerRegistration : public ListenerRegistration {
void Remove() override;

private:
absl::Mutex mutex_;

/** The client that was used to register this listen. */
std::shared_ptr<core::FirestoreClient> client_;
std::shared_ptr<core::FirestoreClient> client_ ABSL_GUARDED_BY(mutex_);

/** The async listener that is used to mute events synchronously. */
std::weak_ptr<core::AsyncEventListener<core::ViewSnapshot>> async_listener_;
std::weak_ptr<core::AsyncEventListener<core::ViewSnapshot>> async_listener_
ABSL_GUARDED_BY(mutex_);

/** The internal QueryListener that can be used to unlisten the query. */
std::weak_ptr<core::QueryListener> query_listener_;
std::weak_ptr<core::QueryListener> query_listener_ ABSL_GUARDED_BY(mutex_);
};

} // namespace api
Expand Down
1 change: 0 additions & 1 deletion scripts/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ python --version
"${top_dir}/scripts/check_copyright.sh"
"${top_dir}/scripts/check_test_inclusion.py"
"${top_dir}/scripts/check_imports.swift"
"${top_dir}/scripts/check_firestore_core_api_absl.py"

# Google C++ style
lint_cmd=("${top_dir}/scripts/check_lint.py")
Expand Down
85 changes: 0 additions & 85 deletions scripts/check_firestore_core_api_absl.py

This file was deleted.