Skip to content
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

Support sync filesystem writing ("flush writes") #571

Open
inaitana opened this issue Jun 21, 2023 · 0 comments
Open

Support sync filesystem writing ("flush writes") #571

inaitana opened this issue Jun 21, 2023 · 0 comments

Comments

@inaitana
Copy link

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.

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

No branches or pull requests

1 participant