-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camera_avfoundation] fix race condition when starting image stream on iOS #8733
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
[camera_avfoundation] fix race condition when starting image stream on iOS #8733
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
89cc825 to
e902881
Compare
|
I'm not sure why but I'm getting a 400 error when signing the CLA (Which I thought I had already signed for other PR) |
|
This will require unit test in order to land. |
|
I'm looking for any example test but I don't see anything. As this doesn't affect the Dart part I don't see how to make a test for this, wouldn't this be test exempt? Additionally, this bug in particular manifests as a race condition in the communication with Dart and native, requiring an end to end test, which I'm not seeing either. |
There is no blanket test exemption for native code; if there were, almost nothing in plugins would be tested. Please see https://github.com/flutter/flutter/blob/master/docs/ecosystem/testing/Plugin-Tests.md |
# Conflicts: # packages/camera/camera_avfoundation/example/ios/Runner.xcodeproj/project.pbxproj # packages/camera/camera_avfoundation/example/ios/RunnerTests/StreamingTest.m
|
I added a test for the issue. Everything was working before this last Swift refactor. A few things:
Again, not an expert in Swift/Objective-C. Also, the test was developed in Master and it failed unless you added a delay before the expect. |
|
Ended up adding the async/await because the tests pass with that, I guess it's because of the callback added to the function? |
The async/await api is generated. Can you use completion callbacks to be consistent with other tests? |
…ondition # Conflicts: # packages/camera/camera_avfoundation/CHANGELOG.md
|
@hellohuanlin I updated the tests to use the completion callback, I had to move the expectation creation step of the streaming test because the existing expectation only were run when actually capturing output. |
|
@hellohuanlin I don't even know what is happening with the formating checks in CI, it keeps flipping between: If I make the change the CI will apply the other formatting. |
I think you're conflating the output for two different files: QueueUtils.m, and QueueUtils.h. I see consistent CI output across each file for the last three runs. The formatting between the files isn't consistent, but that's just a quirk of the header not being identified by |
|
@stuartmorgan Thank you but I'm not sure I'm following, what would be the fix? I'm running the provided format command and it doesn't change anything in the current state of the PR. This is the output |
# Conflicts: # packages/camera/camera_avfoundation/CHANGELOG.md # packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraInitRaceConditionsTests.swift
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed the notification that this was ready for review again and it fell off my radar. Overall it looks good, just some minor issues.
...camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCam.m
Outdated
Show resolved
Hide resolved
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing status; that was meant to be a request-changes comment.
Also, this will need a merge with main, since we can't trigger that from our end since the branch doesn't allow Flutter team members to push to it.
…condition # Conflicts: # packages/camera/camera_avfoundation/CHANGELOG.md # packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraInitRaceConditionsTests.swift # packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCamera.swift # packages/camera/camera_avfoundation/example/ios/RunnerTests/StreamingTests.swift # packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/CameraPlugin.m # packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCam.m # packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/include/camera_avfoundation/FLTCam_Test.h # packages/camera/camera_avfoundation/pubspec.yaml
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's much easier to follow! One nit, and one logic issue that I noticed due to the new diff, and then this will be good to land.
...camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCam.m
Outdated
Show resolved
Hide resolved
...camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation_objc/FLTCam.m
Outdated
Show resolved
Hide resolved
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
| attributes:nil | ||
| error:&error]; | ||
| if (error) { | ||
| BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:fileDir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on this change!
|
autosubmit label was removed for flutter/packages/8733, because - The status or check suite Linux_android_legacy android_platform_tests_legacy_api_shard_1 master has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
@stuartmorgan-g The autosubmit label was removed because of a flaky job, can you guys retry individual jobs or should I keep commiting until it passes? |
flutter/packages@03a6abb...25d4fa4 2025-06-17 22373191+Hari-07@users.noreply.github.com [google_maps_flutter] Add a new zIndexInt param to marker and deprecate zIndex (flutter/packages#8012) 2025-06-17 33691143+JesseRiemens@users.noreply.github.com [pigeon] Use a const for custom type ids for gobject generated files (#156100) (flutter/packages#9306) 2025-06-16 22373191+Hari-07@users.noreply.github.com [google_maps_flutter_platform_(web/android/ios)] Add a new zIndexInt param to marker and deprecate zIndex (flutter/packages#9408) 2025-06-16 jorgesarpe@gmail.com [camera_avfoundation] fix race condition when starting image stream on iOS (flutter/packages#8733) 2025-06-16 engine-flutter-autoroll@skia.org Roll Flutter from f79452e to 8303a96 (21 revisions) (flutter/packages#9433) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…n iOS (flutter#8733) Fixes flutter/flutter#147702 It's not easy to reproduce this with the example application (as shown in the linked issue). We've been able to reproduce it in our own application which makes heavy usage of Platform channels and different native plugins. After digging into the code we notice that: The Dart code that starts listening to the event channel was being executed before initializing the stream in the native side. https://github.com/flutter/packages/blob/9744c9dc4f865cf943776e8c3382b3228b2e7cfd/packages/camera/camera_avfoundation/lib/src/avfoundation_camera.dart#L271 https://github.com/flutter/packages/blob/9744c9dc4f865cf943776e8c3382b3228b2e7cfd/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTThreadSafeEventChannel.m#L31 I don't have much experience with Objective-C, so not sure how to create unit tests for that if necessary but I believe this would be an adecuate solution. I've seen other methods in the plugin that use the same strategy passing the completion object. - [] I added new tests to check the change I am making, or this PR is [test-exempt]. - [] All existing and new tests are passing.
flutter/packages@03a6abb...25d4fa4 2025-06-17 22373191+Hari-07@users.noreply.github.com [google_maps_flutter] Add a new zIndexInt param to marker and deprecate zIndex (flutter/packages#8012) 2025-06-17 33691143+JesseRiemens@users.noreply.github.com [pigeon] Use a const for custom type ids for gobject generated files (flutter#156100) (flutter/packages#9306) 2025-06-16 22373191+Hari-07@users.noreply.github.com [google_maps_flutter_platform_(web/android/ios)] Add a new zIndexInt param to marker and deprecate zIndex (flutter/packages#9408) 2025-06-16 jorgesarpe@gmail.com [camera_avfoundation] fix race condition when starting image stream on iOS (flutter/packages#8733) 2025-06-16 engine-flutter-autoroll@skia.org Roll Flutter from f79452e to 8303a96 (21 revisions) (flutter/packages#9433) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…n iOS (flutter#8733) Fixes flutter/flutter#147702 It's not easy to reproduce this with the example application (as shown in the linked issue). We've been able to reproduce it in our own application which makes heavy usage of Platform channels and different native plugins. After digging into the code we notice that: The Dart code that starts listening to the event channel was being executed before initializing the stream in the native side. https://github.com/flutter/packages/blob/9744c9dc4f865cf943776e8c3382b3228b2e7cfd/packages/camera/camera_avfoundation/lib/src/avfoundation_camera.dart#L271 https://github.com/flutter/packages/blob/9744c9dc4f865cf943776e8c3382b3228b2e7cfd/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTThreadSafeEventChannel.m#L31 I don't have much experience with Objective-C, so not sure how to create unit tests for that if necessary but I believe this would be an adecuate solution. I've seen other methods in the plugin that use the same strategy passing the completion object. - [] I added new tests to check the change I am making, or this PR is [test-exempt]. - [] All existing and new tests are passing.
Fixes flutter/flutter#147702
It's not easy to reproduce this with the example application (as shown in the linked issue). We've been able to reproduce it in our own application which makes heavy usage of Platform channels and different native plugins. After digging into the code we notice that:
The Dart code that starts listening to the event channel was being executed before initializing the stream in the native side.
packages/packages/camera/camera_avfoundation/lib/src/avfoundation_camera.dart
Line 271 in 9744c9d
packages/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTThreadSafeEventChannel.m
Line 31 in 9744c9d
I don't have much experience with Objective-C, so not sure how to create unit tests for that if necessary but I believe this would be an adecuate solution. I've seen other methods in the plugin that use the same strategy passing the completion object.
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.