Repository navigation
Description
Steps to reproduce
Display a continuously rendering external texture (e.g. a WebRTC video stream via flutter_webrtc ≥ 0.12.12, which uses the new TextureRegistry.SurfaceProducer API) in fullscreen on an Android 13+ device, and leave it running.
Expected results
File-descriptor count stays stable; the stream keeps rendering indefinitely.
Actual results
The process leaks one anon:sync_file file descriptor per rendered frame and hits the 32768 RLIMIT_NOFILE ceiling in ~12 min (~2700 fd/min on the test device). After that all new fd operations fail ("Too many open files"), rendering freezes and the app is effectively dead.
Root cause: in the engine, ImageReaderSurfaceProducer.waitOnFence(Image) (and the twin in ImageTextureRegistryEntry) calls image.getFence() and awaitForever() but never fence.close(). SyncFence is AutoCloseable and owns a sync_file fd that the receiver must close. Across the Android embedding there are 2x
getFence() and 0x fence.close(). The fence-wait path is gated on SDK_INT >= 33, so it affects Android 13+. Present in stable 3.41.7 and current master.
Suggested fix — close the fence after awaiting (try-with-resources):
try (SyncFence fence = image.getFence()) {
fence.awaitForever();
} catch (IOException e) { /* drop */ }
Code sample
Code sample
// Flutter engine source: FlutterRenderer.java -> ImageReaderSurfaceProducer.waitOnFence // (stable 3.41.7 and master) @RequiresApi(API_LEVELS.API_33) private void waitOnFence(Image image) { try { SyncFence fence = image.getFence(); fence.awaitForever(); } catch (IOException e) { // Drop. } } // fence (a SyncFence wrapping a sync_file FD) is never close()d.Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
Samsung SM-P619, Android 14. Per-minute fd breakdown from /proc/self/fd:
anon:sync_file 2842 -> 32129 over ~12 min, while socket/file/etc. stay flat.
Then: fcntl(F_DUPFD_CLOEXEC) failed ... Too many open files.
Forcing the legacy SurfaceTexture path (debugForceSurfaceProducerGlTextures=true) did NOT reliably avoid it.
Related: #143777 (closed not planned), #84702, flutter-webrtc/flutter-webrtc#1974.Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.41.7, on Linux Mint 22.3 6.17.0-23-generic, locale de_DE.UTF-8)
• Flutter version 3.41.7 on channel stable at /home/macyo/development/flutter
• Framework revision cc0734ac71 (2026-04-15), Engine revision 59aa584fdf
• Dart version 3.11.5, DevTools version 2.54.2
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Platform android-36, build-tools 35.0.0
• Java version OpenJDK Runtime Environment (build 17.0.18)
• All Android licenses accepted.
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
Activity
mbcorona commentedon Jun 18, 2026
Hi @maCStacker , thanks for the detailed report. Routing to the Android team for investigation.
mboetger commentedon Jun 18, 2026
I believe this is a duplicate of 187222. I took at stab at fixing this with #187267. If you can test with that patch and let me know if the issue still exists that would be great.
mboetger commentedon Jun 18, 2026
It's possible #187216 also fixes it
jason-simmons commentedon Jun 20, 2026
The
flutter-webrtcpackage is using external textures. So this is a different situation from #187222Reproduced this by running the
flutter-webrtcexample app on a Pixel 6a.The
android.hardware.SyncFenceJava object will eventually close the underlying file descriptor when it is garbage collected. But Java GC may not happen promptly, especially in a Flutter app that is doing very few Java operations.The
FlutterRenderertexture classes should instead closeSyncFenceobjects immediately, as suggested in #188161 (comment)[Android] Close FlutterRenderer texture image SyncFence objects immed…
[Android] Close FlutterRenderer texture image SyncFence objects immed…
[Android] Close FlutterRenderer texture image SyncFence objects immed…
JonasJW commentedon Jul 9, 2026
Production confirmation, with two data points that may widen this issue's
scope and priority:
1. This is not limited to flutter_webrtc — plain
video_playerhits it.Our fitness app plays looping exercise videos via video_player 2.10.0 /
video_player_android 2.9.5 (the SurfaceProducer path). Workouts play video
for 30-60 minutes; affected Android 13+ devices (e.g. Samsung SM-A525F,
Android 14) reach the 32768 fd ceiling mid-session.
2. Fleet-level version bisect confirming the regression window.
Zero "Too many open files" events across 90 days of Flutter 3.41.x-built
releases (~15 versions). We upgraded to 3.44.1 on 2026-06-11 and shipped a
build the same day; the first EMFILE event arrived 2026-06-13, and every
3.44-built release since shows them. Interesting nuance for the "present in
3.41.7" note above: in practice our 3.41 fleet never exhausted fds — which is
consistent with @jason-simmons' observation that GC eventually closes the
SyncFence fds; something in the 3.44 era makes the leak outrun GC
deterministically.
What exhaustion looks like at fleet scale (in case others land here from
the symptoms): once fence dup/merge starts failing with EMFILE, the raster
thread blocks forever in
Surface::dequeueBuffer → BufferQueueProducer::waitForFreeSlotThenRelock(on Adreno alsoAdreno-GSL ioctl_kgsl_syncobj_create fail 24), producing either a permanentsilent freeze (UI dead, Dart isolate keeps running — audio continues, no ANR
recorded anywhere) or, if the user touches the screen, an "Input dispatching
timed out" ANR with the main thread in
flutter::SurfaceChanged → fml::AutoResetWaitableEvent::Wait. Happy to share full thread dumps andlogcat captures.
[CP-stable][Android] Close FlutterRenderer texture image SyncFence ob…
chore: bump engine to e1eaecb
github-actions commentedon Jul 23, 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.