Skip to content
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

fix(storage, android): fix an issue that could crash the app when concurrent calls to removeEventListeners were happening #16996

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,26 @@ private String registerEventChannel(String prefix, String identifier, StreamHand
return identifier;
}

private void removeEventListeners() {
for (String identifier : eventChannels.keySet()) {
eventChannels.get(identifier).setStreamHandler(null);
private synchronized void removeEventListeners() {
// Create a list to hold the keys to remove after iteration
List<String> eventChannelKeys = new ArrayList<>(eventChannels.keySet());
for (String identifier : eventChannelKeys) {
EventChannel eventChannel = eventChannels.get(identifier);
if (eventChannel != null) {
eventChannel.setStreamHandler(null);
}
eventChannels.remove(identifier);
}
eventChannels.clear();

for (String identifier : streamHandlers.keySet()) {
streamHandlers.get(identifier).onCancel(null);
// Create a list to hold the keys to remove after iteration
List<String> streamHandlerKeys = new ArrayList<>(streamHandlers.keySet());
for (String identifier : streamHandlerKeys) {
StreamHandler streamHandler = streamHandlers.get(identifier);
if (streamHandler != null) {
streamHandler.onCancel(null);
}
streamHandlers.remove(identifier);
}
streamHandlers.clear();
}

private FirebaseStorage getStorageFromPigeon(
Expand Down
Loading