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
I run a distributed ticketing app on a few Android devices, some of which have a built-in printer.
All the app persistence (sessions and tickets) is managed through files.
After years of cluelessly watching random episodes data loss, I finally tracked down a major issue.
For each new ticket, I overwrite files with a FileWriter (I actually use Ionic with Awesome Cordova's File plugin, but this is irrelevant here).
In this moment, with adb I can even watch the files content get seemingly updated, and read the new content with cat.
After the writing callback, the app prints the ticket, and this is my point of failure: printing generates a power consumption peak, and devices on old batteries might shut off abruptly.
When the device reboots after the unmanaged shutdown, recently written files are empty. Not outdated, just empty, 0 bytes.
I know that async writing is an OS feature (and Android volumes are always mounted async as far as I know), so the plugin does work as expected, but I think there can be more.
Feature Description
Android actually offers a sync method on FileDescriptor since API level 1, which can be used to ensure sync writing.
I implemented support for it in LocalFilesystem.java, and introduced a setSync method in FileWriter.js to set an optional flag to ensure sync writes.
I am currently testing my solution, will start deploying it in production next week, and if it works as expected I will file a PR and add a reference here.
Alternatives or Workarounds
Again, I know async writing is basically default.
But I believe, if this feature won't be implemented, the documentation should at least warn about potential problems.
The text was updated successfully, but these errors were encountered:
Feature Request
Motivation Behind Feature
I run a distributed ticketing app on a few Android devices, some of which have a built-in printer.
All the app persistence (sessions and tickets) is managed through files.
After years of cluelessly watching random episodes data loss, I finally tracked down a major issue.
For each new ticket, I overwrite files with a FileWriter (I actually use Ionic with Awesome Cordova's File plugin, but this is irrelevant here).
In this moment, with adb I can even watch the files content get seemingly updated, and read the new content with cat.
After the writing callback, the app prints the ticket, and this is my point of failure: printing generates a power consumption peak, and devices on old batteries might shut off abruptly.
When the device reboots after the unmanaged shutdown, recently written files are empty. Not outdated, just empty, 0 bytes.
I know that async writing is an OS feature (and Android volumes are always mounted async as far as I know), so the plugin does work as expected, but I think there can be more.
Feature Description
Android actually offers a sync method on FileDescriptor since API level 1, which can be used to ensure sync writing.
I implemented support for it in LocalFilesystem.java, and introduced a setSync method in FileWriter.js to set an optional flag to ensure sync writes.
I am currently testing my solution, will start deploying it in production next week, and if it works as expected I will file a PR and add a reference here.
Alternatives or Workarounds
Again, I know async writing is basically default.
But I believe, if this feature won't be implemented, the documentation should at least warn about potential problems.
The text was updated successfully, but these errors were encountered: