Skip to content

Conversation

rahul-lohra
Copy link
Contributor

🎯 Goal

Resolve file unavailable crash, specially on Chinesse OEMs

Fatal Exception: java.io.FileNotFoundException: /mnt/expand/d741f19b-cac4-44ef-aa92-e8c0402a1b3b/user/0/<packagename>/files/internal_0.txt: open failed: EINVAL (Invalid argument)
       at [libcore.io](http://libcore.io/).IoBridge.open(IoBridge.java:574)
       at [java.io](http://java.io/).FileOutputStream.<init>(FileOutputStream.java:259)
       at io.getstream.log.file.FileStreamLoggerKt.fileWriter(FileStreamLogger.kt:163)
       at io.getstream.log.file.FileStreamLoggerKt.access$fileWriter(FileStreamLogger.kt:1)
       at io.getstream.log.file.FileStreamLogger.initIfNeeded(FileStreamLogger.kt:105)
       at io.getstream.log.file.FileStreamLogger.log$lambda$1(FileStreamLogger.java:69)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
       at java.lang.Thread.run(Thread.java:1012)
   * On some Android 11+ devices (especially Chinese OEMs), we observed that creating files
   * using File(...) and createNewFile() can fail unexpectedly (background/doze modes/RAM cleaning/device cleanup utilities) with FileNotFoundException or EINVAL,
   * even when writing to internal storage.
   * This helper ensures safe creation of files by handling edge cases and logging issues to improve
   * stability across all devices.

🛠 Implementation details

Check if file exists and is writable before we start writing to it

@rahul-lohra rahul-lohra self-assigned this Jul 1, 2025
@rahul-lohra rahul-lohra changed the title Add a safe check before before we start writing logs to file Add a safe check before before we start writing logs Jul 1, 2025
@VelikovPetar VelikovPetar merged commit 4ffb29d into develop Jul 2, 2025
4 checks passed
@VelikovPetar VelikovPetar deleted the bugfix/rahullohra/safe-logging branch July 2, 2025 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants