You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Impeller][Vulkan] CommandPoolVK can free command buffers on a destroyed VkDevice, crashing in vkFreeCommandBuffers on the resource manager thread #186458
1.Run a Flutter app on a Vulkan-enabled Android / Linux device with Impeller (e.g. --enable-impeller).
2.Repeatedly start and kill the app (or rapidly tear down the FlutterEngine / ContextVK).
3.Observe occasional native crashes during shutdown.
This is a teardown-time race; reproduction is timing-dependent but is reliably hit on lower-end devices under memory pressure or fast app-restart loops.
This is the same class of lifetime bug as #166725 ("[Impeller] keep device
holder and allocator alive until last vk image is destroyed"), but on the command pool teardown path which was not touched in that PR.
Expected results
The application shuts down cleanly. vkDestroyCommandPool / vkFreeCommandBuffers should never be issued through a VkDevice that has already been destroyed.
Hi @ZhongNing1
The flutter doctor screenshot shows Flutter 2.35.7, which is well behind current stable (3.41.9). Could you first confirm whether this still reproduces on a recent stable or main build? Impeller's resource lifetime handling has had a number of changes since then, and it's possible this teardown path has already been addressed.
If it does still reproduce, please also attach:
Full flutter doctor -v output (text, not screenshot)
The complete crash log / stack trace
Affected device(s) and OS version
Hi @ZhongNing1 The flutter doctor screenshot shows Flutter 2.35.7, which is well behind current stable (3.41.9). Could you first confirm whether this still reproduces on a recent stable or main build? Impeller's resource lifetime handling has had a number of changes since then, and it's possible this teardown path has already been addressed. If it does still reproduce, please also attach:
Full flutter doctor -v output (text, not screenshot) The complete crash log / stack trace Affected device(s) and OS version
Sorry, due to certain reasons, we are unable to upgrade to version 3.41.9. However, from a code analysis perspective, this issue still persists in version 3.41.9.
Given the specific signature (vkFreeCommandBuffers on destroyed VkDevice via CommandPoolRecyclerVK::Reclaim) and reference to the related #166725 fix which didn't cover this path, routing to the engine team for review of the lifetime guarantees rather than another repro request.
The ContextVK owns the ResourceManagerVK. So in theory the ResourceManagerVK thread that deletes BackgroundCommandPoolVK instances should only be running while the ContextVK and its Vulkan device are alive.
I'd like to get a better understanding of how a BackgroundCommandPoolVK was destructed after the Vulkan device was destroyed.
The ContextVK owns the ResourceManagerVK. So in theory the ResourceManagerVK thread that deletes BackgroundCommandPoolVK instances should only be running while the ContextVK and its Vulkan device are alive.
I'd like to get a better understanding of how a BackgroundCommandPoolVK was destructed after the Vulkan device was destroyed.
The buffers.clear() line that calls vkFreeCommandBuffers happens after a call to context_.lock() that acquires a std::shared_ptr<ContextVK>. That indicates that the ContextVK associated with this CommandPoolRecyclerVK is alive, and it should contain a DeviceHolderVK with an active VkDevice.
Can you confirm that the crash happens after the context_.lock() succeeds?
If the ContextVK and its VkDevice are alive, then another possibility is that somehow one of the command buffers freed by CommandPoolRecyclerVK::Reclaim is bound to a different device.
Try adding logging like this to CommandPoolRecyclerVK::Reclaim:
Each vk::UniqueCommandPool and vk::UniqueCommandBuffer has an owner VkDevice that is used to delete the object. The VkDevice bound to these objects should be the same as the VkDevice held by the ContextVK.
If there is a mismatch and the objects are owned by a different device which has been destroyed, then that could cause an error when the Vulkan objects are deleted.
Also, is the application doing anything unusual such as creating multiple instances of the Flutter engine? Or using the FlutterEngineGroup engine cloning APIs?
The issue does not involve the use of multiple engines or FlutterEngineGroup scenarios. The probability of this issue recurring in a similar scenario is low. Could the current issue be caused by insufficient memory?
It's unclear whether memory or other resource limitations could be a factor. Without a way to reproduce the issue, it's hard to determine why the vkFreeCommandBuffers call was failing.
Yes, we also hit this during stability testing, and I agree it is very hard to reproduce deterministically.
That said, from a code perspective, this looks like the same class of lifetime issue as #166725: Vulkan objects are being destroyed on a background thread after the underlying VkDevice may already be gone.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
mbcorona commentedon May 13, 2026
Thanks for the detailed analysis and the reference to #166725.
To help them act on this, could you provide:
flutter doctor -v output
Full crash log / stack trace (the snippet above appears truncated)
Affected device(s) and OS version
ZhongNing1 commentedon May 14, 2026
mbcorona commentedon May 14, 2026
Hi @ZhongNing1
The flutter doctor screenshot shows Flutter 2.35.7, which is well behind current stable (3.41.9). Could you first confirm whether this still reproduces on a recent stable or main build? Impeller's resource lifetime handling has had a number of changes since then, and it's possible this teardown path has already been addressed.
If it does still reproduce, please also attach:
Full flutter doctor -v output (text, not screenshot)
The complete crash log / stack trace
Affected device(s) and OS version
ZhongNing1 commentedon May 15, 2026
Sorry, due to certain reasons, we are unable to upgrade to version 3.41.9. However, from a code analysis perspective, this issue still persists in version 3.41.9.
mbcorona commentedon May 15, 2026
Given the specific signature (vkFreeCommandBuffers on destroyed VkDevice via CommandPoolRecyclerVK::Reclaim) and reference to the related #166725 fix which didn't cover this path, routing to the engine team for review of the lifetime guarantees rather than another repro request.
3 remaining items
ZhongNing1 commentedon May 19, 2026
The demo code is quite extensive and was generated during the stability test. It is necessary to make the following modifications.
resolve_crash_diff.txt
jason-simmons commentedon May 20, 2026
@ZhongNing1 Do you have a more complete stack trace for the situation shown in #186458 (comment)?
The
ContextVKowns theResourceManagerVK. So in theory theResourceManagerVKthread that deletesBackgroundCommandPoolVKinstances should only be running while theContextVKand its Vulkan device are alive.I'd like to get a better understanding of how a
BackgroundCommandPoolVKwas destructed after the Vulkan device was destroyed.ZhongNing1 commentedon May 20, 2026
@jason-simmons
jason-simmons commentedon May 20, 2026
The implementation of
CommandPoolRecyclerVK::Reclaimin version3.35.7is:https://github.com/flutter/flutter/blob/3.35.7/engine/src/flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc#L276
The
buffers.clear()line that callsvkFreeCommandBuffershappens after a call tocontext_.lock()that acquires astd::shared_ptr<ContextVK>. That indicates that theContextVKassociated with thisCommandPoolRecyclerVKis alive, and it should contain aDeviceHolderVKwith an activeVkDevice.Can you confirm that the crash happens after the
context_.lock()succeeds?If the
ContextVKand itsVkDeviceare alive, then another possibility is that somehow one of the command buffers freed byCommandPoolRecyclerVK::Reclaimis bound to a different device.Try adding logging like this to
CommandPoolRecyclerVK::Reclaim:Each
vk::UniqueCommandPoolandvk::UniqueCommandBufferhas an ownerVkDevicethat is used to delete the object. TheVkDevicebound to these objects should be the same as theVkDeviceheld by theContextVK.If there is a mismatch and the objects are owned by a different device which has been destroyed, then that could cause an error when the Vulkan objects are deleted.
Also, is the application doing anything unusual such as creating multiple instances of the Flutter engine? Or using the
FlutterEngineGroupengine cloning APIs?ZhongNing1 commentedon May 21, 2026
The issue does not involve the use of multiple engines or FlutterEngineGroup scenarios. The probability of this issue recurring in a similar scenario is low. Could the current issue be caused by insufficient memory?
jason-simmons commentedon May 21, 2026
It's unclear whether memory or other resource limitations could be a factor. Without a way to reproduce the issue, it's hard to determine why the
vkFreeCommandBufferscall was failing.ZhongNing1 commentedon May 22, 2026
@jason-simmons
Yes, we also hit this during stability testing, and I agree it is very hard to reproduce deterministically.
That said, from a code perspective, this looks like the same class of lifetime issue as #166725: Vulkan objects are being destroyed on a background thread after the underlying
VkDevicemay already be gone.Saves a DeviceHolderVK with the CommandPoolVK (flutter#186749)
gaaclarke commentedon May 22, 2026
@ZhongNing1, a fix has landed on the
mainchannel based on your patch in #186458 (comment) ( #186749 )Try that out, please.
Saves a DeviceHolderVK with the CommandPoolVK (flutter#186749)
github-actions commentedon Aug 11, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.